I hv This Question here:

User will be prompt for number of quiz that has been taken.
User has to input their marks for each quiz.
Your program will calculate the average of the marks.
Find the lowest mark of those quizzes.
Find the 3 highest mark of those quizzes.
Those highest marks must be in order (from highest to lowest).

eg:

Number of quiz taken : 5
Please input mark for quiz 1: 10
Please input mark for quiz 2: 30
Please input mark for quiz 3: 20
Please input mark for quiz 4: 40
Please input mark for quiz 5: 60

Your average mark is 32.
Your lowest mark is 10.
The three highest marks for your quizzes are 60, 40, 30.

And i can just make it until :

#include<stdio.h>

int main()
{
    int count,num;
    float mark[10];
    float total=0,avg;
    float lowest,highest;

    printf("Number of quiz taken : " );
    scanf("%d",&num);
    for(count=0;count<num; count++)
	{
		printf(" Please input mark for quiz %d: ",count+1);
        scanf("%f",&mark[count]);
        
		total=total+mark[count];
    }
    avg=total/num;
    printf("Your average mark is %.2f.\n",avg);
    lowest=mark[0];
    for(count=0;count<num;count++)
	{
		if(mark[count] < lowest)
		{
			lowest=mark[count];
		}
    }
    printf("Your lowest mark is %.2f.\n",lowest);

	highest=mark[0];
	for(count=0;count<num;count++)
	{
		if(mark[count] > highest)
		{
			highest=mark[count];
		}
    }
	printf("Your highest mark is %.2f.\n",highest);
}

anybody tell me how to make the 2nd and 3rd highest marks?
i cant figure it out...
thanks...

Recommended Answers

All 4 Replies

This will helps ;)

#define MAXSIZE 10
#include <stdio.h>

int main()
{
	int num,index,next;
	float mark[MAXSIZE];
	float total=0,avg,temp;

	printf("Number of quiz taken(integer between 3 and %d) : ",MAXSIZE);
	scanf("%d",&num);

	if(num < 3 || num > MAXSIZE)
	{
		do
		{
			printf("\n");
			printf("Please enter an integer between 3 and %d) : ",MAXSIZE);
			scanf("%d",&num);
		}while(num < 3 || num > MAXSIZE);
	}

	// get input data from user and calculate the 'total mark' in for loop and 'average mark' after for loop
	for(index = 0;index < num;index++)
	{
		printf("\n");
		printf("Please input mark for quiz %d: ",index+1);
		scanf("%f",&mark[index]);

		total = total + mark[index];
	}

	avg	= total/num;

	// sorting the array with ascending order
	for(index = 0;index < num;index++)
		for(next = index+1;next < num;next++)
			if(mark[index] < mark[next])
			{
				temp		= mark[index];
				mark[index]	= mark[next];
				mark[next]	= temp;
			}

	printf("\n");
	printf(" - Quiz Statistic:\n");
	printf(" - Your average mark is %.2f.\n",avg);
	printf(" - Your lowest mark is %.2f.\n",mark[num-1]);
	printf(" - The three highest marks for your quizzes are %.2f, %.2f, %.2f.\n\n",mark[0],mark[1],mark[2]);
}

by Kevin from Anhui University of P.R.China

In the sorting algorithm, for(index = 0;index < num;index++) should be for(index = 0;index < num-1;index++) That's one extra useless iteration to perform.

Also, if num=10, then in your code, when index = 9, next = 10. Then mark[next] (which is mark[10]) will have a garbage value.

thanks guys.
this is the way to make it.
learnt something 2day...
thanks again ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.