From cd119beb8f3fcec97274563f6a5455080a76fdf6 Mon Sep 17 00:00:00 2001 From: Utkarsh Bajpai <64923342+Utkarsh-byte-bot@users.noreply.github.com> Date: Sun, 3 Oct 2021 12:35:02 +0530 Subject: [PATCH] Update question1.c This will provide you a sorted array in ascending in order. --- question1.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/question1.c b/question1.c index 3482bb2..93a17ef 100644 --- a/question1.c +++ b/question1.c @@ -1 +1,37 @@ // Sort an array using c programing langauge + #include + void main() + { + + int i, j, a, n, number[30]; + printf("Enter the value of N \n"); + scanf("%d", &n); + + printf("Enter the numbers \n"); + for (i = 0; i < n; ++i) + scanf("%d", &number[i]); + + for (i = 0; i < n; ++i) + { + + for (j = i + 1; j < n; ++j) + { + + if (number[i] > number[j]) + { + + a = number[i]; + number[i] = number[j]; + number[j] = a; + + } + + } + + } + + printf("The numbers arranged in ascending order are given below \n"); + for (i = 0; i < n; ++i) + printf("%d\n", number[i]); + + }