View Code of Problem 83

#include<stdio.h>
 struct student{
	int no;
	int score;
};
int main(){
	int m,n;
	int t1,t2;
	scanf("%d %d\n",&n,&m);
		student stu[n+m];
		for(int i=0;i<m+n;i++){
		scanf("%d %d",&stu[i].no,&stu[i].score);
	}
	for(int i=0;i<m+n-1;i++){
		for(int j=0;j<m+n-i-1;j++){
			if(stu[j].no>stu[j+1].no){
				t1=stu[j].no;t2=stu[j].score;
				stu[j].no=stu[j+1].no;
				stu[j].score=stu[j+1].score;
				stu[j+1].no=t1;
				stu[j+1].score=t2;
				
			}
		}
		
	}
	
	for(int i=0;i<m+n;i++){
		printf("%d %d\n",stu[i].no,stu[i].score);
	}
	
	
	return 0;
}
/*
Main.c: In function 'main':
Main.c:10:3: error: unknown type name 'student'
   student stu[n+m];
   ^
Main.c:12:24: error: request for member 'no' in something not a structure or union
   scanf("%d %d",&stu[i].no,&stu[i].score);
                        ^
Main.c:12:35: error: request for member 'score' in something not a structure or union
   scanf("%d %d",&stu[i].no,&stu[i].score);
                                   ^
Main.c:16:13: error: request for member 'no' in something not a structure or union
    if(stu[j].no>stu[j+1].no){
             ^
Main.c:16:25: error: request for member 'no' in something not a structure or union
    if(stu[j].no>stu[j+1].no){
                         ^
Main.c:17:14: error: request for member 'no' in something not a structure or union
     t1=stu[j].no;t2=stu[j].score;
              ^
Main.c:17:27: error: request for member 'score' in something not a structure or union
     t1=stu[j].no;t2=stu[j].score;
                           ^
Main.c:18:11: error: request for member 'no' in something not a structure or union
     stu[j].no=stu[j+1].no;
           ^
Main.c:18:23: error: request for member 'no' in something not a structure or union
     stu[j].no=stu[j+1].no;
                       ^
Main.c:19:11: error: request for member 'score' in something not a structure or union
     stu[j].score=stu[j+1].score;
           ^
Main.c:19:26: error: request for member 'score' in something not a structure or union
     stu[j].score=stu[j+1].score;
                          ^
Main.c:20:13: error: request for member 'no' in something not a structure or union
     stu[j+1].no=t1;
             ^
Main.c:21:13: error: request for member 'score' in something not a structure or union
     stu[j+1].score=t2;
             ^
Main.c:29:26: error: request for member 'no' in something not a structure or union
   printf("%d %d\n",stu[i].no,stu[i].score);
                          ^
Main.c:29:36: error: request for member 'score' in something not a structure or union
   printf("%d %d\n",stu[i].no,stu[i].score);
                                    ^
Main.c:10:11: warning: variable 'stu' set but not used [-Wunused-but-set-variable]
   student stu[n+m];
           ^
*/

Double click to view unformatted code.


Back to problem 83