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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started