Input the marks of ten students and display their average. Use for loop for this purpose

–1 vote

answered Oct 5 by paraboy
int arr;double sum=0;

for(int i=0;i<10;i++)

{

cin>>arr[i];

sum=sum+arr[i];

}

sum=sum/10;

cout<<"Average of 10 students is "<<sum<<endl;
answered 6 days ago by anonymous
#include <stdio.h>

/**
* Code to work out average of results from 10 students entered
*/

int main(){

/*
result and sum can be float etc for more precision since
if results can be .25 and sum could be a decimal result as a result
*/

int counter, result, sum;
double avg;     // double for precision

//For loop to enter scores for 10 students, and work out sum on each pass
for(counter = 0; counter < 10; counter++){
printf("Please enter result for student %d: ", counter+1);
scanf("%d", &result[counter+1]);

//sum = current sum value + value in array
sum +=result[counter+1];
}

avg = (double)sum / (double)10;         //typecast for precision. Not required necessarily

printf("Average result is %f", avg);

return 0;
}
answered 2 days ago by anonymous
#include <stdio.h>
#include<conio.h>

#include <stdio.h>

main()
{
char arr;
double avg=0;
int sum=0;

for(int i=1;i<=10;i++)

{

printf("Enter %dth sutadnt marks: ",i);
scanf("%s",&arr[i]);

sum=sum+arr[i];

}

avg=sum/10;

printf("Average of 10 students is %g\n",avg);
}
answered 2 days ago by anonymous
#include <stdio.h>
#include<conio.h>
main()
{
char arr;
double avg=0;
int sum=0;
for(int i=1;i<=10;i++)

{
printf("Enter %dth sutadnt marks: ",i);
scanf("%s",&arr[i]);
sum=sum+arr[i];
}
avg=sum/10;
printf("Average of 10 students is %g\n",avg);
}