C programming code to settle increasing and decreasing order using switch case and bubble shot | C Programming


#include<stdio.h>


int main()


{


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


char choice;


{


printf("Press a for ascending and d for descending:");


scanf("%c",&choice);


   printf("How many numbers to be inputed?");


scanf("%d",&n);


     printf("\n\nEnter number one by one:\n");


for(i=0;i<n;i++)


{


scanf("%d",&a[i]);


}


switch(choice)


   {


case'a':


for(i=0;i<n;i++)


{


for(j=0;j<n-i-1;j++)


{


if(a[j]>a[j+1])


{


temp=a[j];


a[j]=a[j+1];


a[j+1]=temp;


}


}


}


printf("\n\nThe number in ascending order is:\n");


for(i=0;i<n;i++)


{


printf("%d\n",a[i]);


}


break;


case 'd':


for(i=0;i<n;i++)


{


for(j=0;j<n-i-1;j++)


{


if(a[j]<a[j+1])


{


temp=a[j];


a[j]=a[j+1];


a[j+1]=temp;


}


}


}


printf("The number in descending order is:\n");


for(i=0;i<n;i++)


{


printf("%d\n",a[i]);


}


break;


default:


printf("Case is invalid!!");


}


}


}

OUTPUT


C program to settle increasing and decreasing order using switch case and bubble shot



Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours