### Prog 355: Average of best two test marks out of given number of test marks

Program 355: Average of best two test marks out of given number of test marks
```#include<stdio.h>
main()
{
int i,size,max,max2,position;
printf("Enter size to find average of 2 best text marks out of given size\n");
scanf("%d",&size);
int a[size],temp[size-1];
printf("Enter numbers in array\n");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
position=0;

for(i=0;i<size;i++)//find first max number
{
if(a[i]>max)
{
max=a[i];
position=i;
}
}
for(i=0;i<size-1;i++)//deleting first maximum number in array
{
if(i<position)
{
temp[i]=a[i];
}
if(i>=position)
{
temp[i]=a[i+1];
}

}
max2=temp[0];
printf("\n");
for(i=0;i<size-1;i++)//finding second max in the remaining elements
{
if(temp[i]>max2)
{
max2=temp[i];

}
}

printf("Average of 2 best out of %d test marks is %d + %d/2=%f\n",size,max,max2,((max+max2)/2.0));

}
```
Explanation:

//Coming Soon...

Output:

#### 4 comments:

1. Can I get this same program but using functions..?

1. #include
main()
{
int i,size,max,max2,position;
printf("Enter size to find average of 2 best text marks out of given size\n");
scanf("%d",&size);
int a[size],temp[size-1];
printf("Enter numbers in array\n");
for(i=0;imax)
{
max=a[i];
position=i;
}
}
for(i=0;i=position)
{
temp[i]=a[i+1];
}

}
max2=temp[0];
printf("\n");
for(i=0;imax2)
{
max2=temp[i];

}
}

printf("Average of 2 best out of %d test marks is %d + %d/2=%f\n",size,max,max2,((max+max2)/2.0));

}

2. Can I get this same program using functions but for best 3 out of given number?

2. Can I get this same program using functions but for best 3 out of given numbers?

 Donate Buy me a coffee \$2.00 USD Buy me a burger \$5.00 USD Buy me a pizza \$10.00 USD
 Compiler Used by me C-Free 5.0(Recommended) Other Compilers Code Blocks(Recommended) Online Compilers Ideone(Remember to give input before executing online where ever necessary)