Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
/*Program to print marks of students in ascending order using structure */
#include<stdio.h>
int main()
{
	int n,c,t;
	printf("Enter Total No Of Students\n");
	scanf("%d",&n);
	c=getchar();
	struct student
	{
	char name[100];
	char section;
	int marks[5];
	}s[n];
		
	for(int i=0;i<n;i++)
	{
		printf("Enter Name :");
		gets(s[i].name);
		printf("\n");
		printf("Enter Section :");
		scanf("%c",&s[i].section);
		printf("\n");
		printf("Enter Marks In 5 Subjects \n");
		for(int j=0;j<5;j++)
		{
			scanf("%d",&(s[i].marks[j]));
		}
		c=getchar();
	}
	for(int i=0;i<n;i++)
	{
		for(int k=0;k<5;k++)
		{
			for(int j=0;j<4;j++)
			{
				if(s[i].marks[j]>s[i].marks[j+1])
				{
					t=s[i].marks[j];
					s[i].marks[j]=s[i].marks[j+1];
					s[i].marks[j+1]=t;
				}
			}
		}	
	}
	for(int i=0;i<n;i++)
	{
		printf("\n\nName\tSection\n");
		printf("%s\t%c\t\n",s[i].name,s[i].section);
		printf("Marks In 5 Subjects \n");
		for(int j=0;j<5;j++)
		{
			printf("%d \n",(s[i].marks[j]));
		}
	}			
	return 0;
}


What I have tried:

This code is not printing the output,I want user to enter data of students and marks in 5 subject & the program will sort marks in ascending order and print the data.
Posted
Updated 23-May-18 3:20am
v2

1 solution

The 'missing output' is probably related to the IDE you are using. Try to put a getchar call just before the last statement (return 0;) in order to pause execution and see the output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900