please me rum program... please.
write program declare 3 sets of array.
first array accept 5 integers arranged in ascending order , stored in such order in second array. third array should contain same set of numbers, however, time, integers arranged in descending order.
display output in 3 columns representing 3 arrays subscripts.
also, program should display number has highest , lowest value.
have made program output not yet in 3 columns. , doesnt display output of highest , lowest number yet.
#include<stdio.h>
#include<conio.h>
void main(){
int i,j,k,l,temp,mark[5];
for(i=0;i<5;i++){
printf("first array. enter integer: %d:", i);
scanf("%d",&mark[i]);
}
(i=0;i<5;i++)
for(j=i+1;j<5;j++)
{
if(mark[i]>mark[j])
{
temp=mark[j];
mark[j]=mark[i];
mark[i]=temp;
}}
printf("\n \nsecond array in ascending order:");
for(i=0;i<5;i++)
{
printf("\n%d",mark[i]);
}
printf("\n \n");
(i=0;i<5;i++)
for(j=i+1;j<5;j++)
{
if(mark[i]<mark[j])
{
temp=mark[j];
mark[j]=mark[i];
mark[i]=temp;
}}
printf("\nthird array in descending order:");
for(i=0;i<5;i++)
{
printf("\n%d",mark[i]);
}
printf("\n \n \n");
getch();
}
thank you.
although know homework, since i'm newbie myself, i'm using give myself practice.
p.s: please indent code, hard read (not mine better in terms of style). use spell checker.code:#include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { int mark[5], kram[5],markp[5]; int i,tp,k; char marks[5]; char *endptr; /*assigning arrays*/ for(i=0;i<5;i++) { printf("first array. enter integer: %d \n",i); fgets(marks,5,stdin); mark[i]=strtol(marks,&endptr,10); markp[i]=mark[i]; } /*ascending order*/ k=1;//give positive value first start loop while (k>0) { k=0; for (i=1;i<5;i++) { if (markp[i]<markp[i-1]) { k++; tp=markp[i]; markp[i]=markp[i-1]; markp[i-1]=tp; } } } /*descending order*/ for (i=0;i<5;i++) kram[4-i]=markp[i]; /*printing assigned arrays*/ printf("\nthe arrays printed out\n"); for (i=0;i<5;i++) { printf("%d \t %d \t %d\n",mark[i],markp[i],kram[i]); } /*printing maximum values * every other array has same value so*/ printf("maximum values=%d, minimum values=%d\n",markp[0],markp[4]); return 0; }
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Tthree sets of Array to be displayed in three columns
Ubuntu
Comments
Post a Comment