J
jim
i want to make a c file that i can 'scanf ' students scores of 2
classes and their names , and i want it to get the sum of the 2 scores
and make them in order .at last 'printf'
/*am sorry,my english is not very good ,so u may have some difficulties
in understanding my meaning ,but u can see the follow c file .
thank u !*/
int sum(int a[10][3])
{
int i;
for(i=0;i<10;i++)
{
a[2]=a[1]+a[0];
}
}
int px(int a[10][3],char s[10][6])
{
int i,j,t;
char c[6];
for(i=0;i<10;i++)
{
for(j=0;j<9-i;j++)
{
if(a[j][2]>a[j+1][2])
{
t=a[j][2];
a[j][2]=a[j+1][2];
a[j+1][2]=t;
t=a[j][0];
a[j][0]=a[j+1][0];
a[j+1][0]=t;
t=a[j][1];
a[j][1]=a[j+1][1];
a[j+1][1]=t;
strcpy(c,s[j]);
strcpy(s[j],s[j+1]);
strcpy(s[j+1],c);
}
}
}
}
#include<string.h>
void main()
{
int i,a[10][3];
char s[10][6];
for(i=0;i<10;i++)
{
printf("%d,name,maths,engli,sumhe\n",i );
scanf("%s,%d,%d",s[0],&a[0],&a[1]);
}
sum(a);
px(a,s);
printf("mc ,name,maths,engli,sumhe\n");
for(i=0;i<10;i++)
{
printf("%3d,%5s,%5d,%5d,%5d\n",i,s,a[0],a[1],a[2]);
}
}
classes and their names , and i want it to get the sum of the 2 scores
and make them in order .at last 'printf'
/*am sorry,my english is not very good ,so u may have some difficulties
in understanding my meaning ,but u can see the follow c file .
thank u !*/
int sum(int a[10][3])
{
int i;
for(i=0;i<10;i++)
{
a[2]=a[1]+a[0];
}
}
int px(int a[10][3],char s[10][6])
{
int i,j,t;
char c[6];
for(i=0;i<10;i++)
{
for(j=0;j<9-i;j++)
{
if(a[j][2]>a[j+1][2])
{
t=a[j][2];
a[j][2]=a[j+1][2];
a[j+1][2]=t;
t=a[j][0];
a[j][0]=a[j+1][0];
a[j+1][0]=t;
t=a[j][1];
a[j][1]=a[j+1][1];
a[j+1][1]=t;
strcpy(c,s[j]);
strcpy(s[j],s[j+1]);
strcpy(s[j+1],c);
}
}
}
}
#include<string.h>
void main()
{
int i,a[10][3];
char s[10][6];
for(i=0;i<10;i++)
{
printf("%d,name,maths,engli,sumhe\n",i );
scanf("%s,%d,%d",s[0],&a[0],&a[1]);
}
sum(a);
px(a,s);
printf("mc ,name,maths,engli,sumhe\n");
for(i=0;i<10;i++)
{
printf("%3d,%5s,%5d,%5d,%5d\n",i,s,a[0],a[1],a[2]);
}
}