From e2896d46fd3680f49d967167a7b7ce03f65ffb2f Mon Sep 17 00:00:00 2001 From: Spandan Saxena <55998628+the-rebooted-coder@users.noreply.github.com> Date: Tue, 1 Oct 2019 19:46:39 +0530 Subject: [PATCH] Update insertion-sort.c --- IntroductionToAlgorithms/insertion-sort.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/IntroductionToAlgorithms/insertion-sort.c b/IntroductionToAlgorithms/insertion-sort.c index 65527c8..d1a2de2 100755 --- a/IntroductionToAlgorithms/insertion-sort.c +++ b/IntroductionToAlgorithms/insertion-sort.c @@ -2,15 +2,16 @@ int main() { - int i; - int a[6]={31, 41, 59, 26, 41, 58}; - for(i = 0; i < 6; i++) { - printf("%d\t",a[i]); + int i,n; + printf("Enter the Number of Elements\n"); + scanf("%d",&n); + for(i = 0; i < n; i++) { + scanf("%d",a[i]); } printf("\n"); int key, j = 0; - for(j = 1; j < 6; j++) { + for(j = 1; j < n; j++) { key = a[j]; i = j - 1; @@ -22,7 +23,7 @@ int main() } printf("Sort Complete!\n"); - for(i = 0; i < 6; i++) { + for(i = 0; i < n; i++) { printf("%d\t", a[i]); } printf("\n");