ADS

C Programming Code To Settle Increasing And Decreasing Order Using Switch Case And Bubble Shot | C Programming

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



Post a Comment

0 Comments