C program to print the number in ascending order.

 

C program
C PROGRAM

C program to print the number in ascending order

#include <stdio.h>
#include<conio.h>
void main()
{
  int a[30],n,temp,i,j;
  clrscr();
  printf("enter the values of N \n");
  scanf("%d",&n);
  printf("enter the numbers \n");
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
      for(j=i+1;j<n;j++)
      {
        if(a[i]>a[j])
        {
          temp=a[i];
          a[i]=a[j];
          a[j]=temp;
          }
          }
          }
          printf("the number is arranged in ascending order \n");
          for(i=0;i<n;i++)
          {
          printf("%d \n",a[i]);
          }
          getch();
          }

OUTPUT :

enter the values of N 
5
enter the numbers 
290
18
80
20
48
the number is arranged in ascending order 
18 
20 
48 
80 
290 
Process finished.

No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.