Program 355: Average of best two test marks out of given number of test marks
//Coming Soon...
Output:
#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:
Can I get this same program but using functions..?
ReplyDelete#include
Deletemain()
{
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));
}
Can I get this same program using functions but for best 3 out of given number?
DeleteCan I get this same program using functions but for best 3 out of given numbers?
ReplyDelete