Contact Learn C
Copy Program Share Program

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:

Average of best two test marks out of given number of test marks


Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide