C program to print or find C program to find average of two best test marks out of given number of test marks.
In this tutorial we will solve a problem that find or print the C program to find average of two best test marks out of given number of test marks.
Here we will write a c program source code to print or find the average of test marks or numbers.
This program will accept the range or size of an array that entered by user through the keyboard.
After it we will enter the elements of this array.
After these steps compiler check and execute the conditions and print the average of best two test marks.
C PROGRAM CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int x,size,max1,max2,position;
int array[50],temp[50-1];
clrscr();
printf("\n ENTER SIZE TO FIND AVERAGE OF TWO BEST TEST MARKS OUT OF GIVEN SIZE IN THIS ARRAY:\n ");
scanf("%d",&size);
printf("\n ENTER THE ELEMENTS IN THIS ARRAY:\n ");
for(x=0;x<size;x++)
{
scanf("%d",&array[x]);
}
max1=array[0];
position=0;
for(x=0;x<size;x++)
//find first max number
{
if(array[x]>max1)
{
max1=array[x];
position=x;
}
}
for(x=0;x<size-1;x++)
//deleting first maximum number in array
{
if(x<position)
{
temp[x]=array[x];
}
if(x>=position)
{
temp[x]=array[x+1];
}
}
max2=temp[0];
printf("\n ");
for(x=0;x<size-1;x++)
//finding second max in the remaining elements
{
if(temp[x]>max2)
{
max2=temp[x];
}
}
printf("\n AVERAGE OF TWO BEST OUT OF %d TEST MARKS IS \n %d + %d / 2 = %f\n",size,max1,max2,((max1+max2)/2.0));
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment