Assume that the array X is defined and initialized with the following statement:
ID: 3688223 • Letter: A
Question
Assume that the array X is defined and initialized with the following statement: double X[]= {2.5, 1.5,4.0, 7.0, 3.5, 6.5, 8.5, 1.0}; Write two C programs to sort this array. One is in ASCENDING order. The other is in DESCENDING order. Print out the two sorted arrays. Write a C program that calculates three separated SUMS for columns 1, 3 and 4 of the following two-dimensional array. Print out the three separated sums. ONE SUM PER LINE is required. Please turn in the computer print outs of the C programs, the compiling steps and the resultsExplanation / Answer
#include<stdio.h>
#include<conio.h>
void main()
{
double x[]={2.5,1.5,4.0,7.0,3.5,6.5,8.5,1.0},b,c;
int i,j;
clrscr();
for(i=0;i<8;i++)
{
for(j=0;j<=i;j++)
{
if(x[j]>x[i])
{
c=x[j];
x[j]=x[i];
x[i]=c;
}
}
}
printf(" Ascending Sorted Arrary is :-");
for(i=0;i<8;i++)
{
printf(" %lf",x[i]);
}
for(i=0;i<8;i++)
{
for(j=0;j<=i;j++)
{
if(x[j]<x[i])
{
c=x[j];
x[j]=x[i];
x[i]=c;
}
}
}
printf(" Descending Sorted Arrary is :-");
for(i=0;i<8;i++)
{
printf(" %lf",x[i]);
}
getch();
}
2.
#include<stdio.h>
#include<conio.h>
void main()
{
int x[6][6];
int s=0,i,j,c=1;
clrscr();
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
x[i][j]=c;
c++;
}
}
for(i=0;i<6;i++)
{
s=s+x[i][1];
}
printf("Sum of first column=%d",s);
s=0;
for(i=0;i<6;i++)
{
s=s+x[i][3];
}
printf("Sum of third column=%d",s);
s=0;
for(i=0;i<6;i++)
{
s=s+x[i][4];
}
printf("Sum of fourth column=%d",s);
getch();
}