Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions