Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
678 B
1
Indexable
Never
#include <stdio.h>
#include <string.h>

void main()
{
//wap to input integer number and sort them in ascending order

int num[100];
int i,j,temp,n;

printf("Enter the number of elements in an array :\n");
scanf("%d",&n);

printf("Enter the elements:\n");
   for (i = 0; i < n; i++){
      scanf("%d", &num[i]);
   }
   for (i = 0; i < n-1; i++){
      for (j = 0; j < n-i-1; j++){
         if (num[j] > num[j+1]){
            temp = num[j];
            num[j] = num[j+1];
            num[j+1] = temp;
         }
      }
   }

     printf("The numbers in ascending order is: \n ");
   for (i = 0; i < n; i++){
      printf("%d\n", num[i]);
   }
}
Leave a Comment