Question: 1. a) Write a C program that will take a series of n integers as input in an array and sort the series in both

1. a) Write a C program that will take a series of n integers as input in an array and sort the series in both ascending and descending order.

Sample input:

5

10 15 45 5 0

Sample output:

Ascending Order: 0 5 10 15 45

Descending Order: 45 15 10 5 0

b)Analyze the following C programs and find if there is any error. Write the corrected version of the programs and find the valid output for them with proper explanation.

i.

#include

int main()

{

int i=5; char ch;

scanf("%c",ch); //input B switch(ch)

{

case A:

printf("%d ",++i); break

case B:

printf("%d ",++i); case C:

printf("%d ",++i); case 'D':

printf("%d ",i++); break

}

}

ii.

#include

int main() {

int i, j=2;

for(i=0: j>0, i<5: i++)

{

printf("%d \t",i+j); j--;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!