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

–1 vote
asked Oct 5 by jawad

4 Answers

0 votes
answered Oct 5 by paraboy
int arr[10];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;
0 votes
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[10], 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;
}
0 votes
answered 2 days ago by anonymous
#include <stdio.h>
#include<conio.h>

#include <stdio.h>

 main()
{
    char arr[10];
    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);
}
0 votes
answered 2 days ago by anonymous
#include <stdio.h>
#include<conio.h>
 main()
{
    char arr[10];
    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);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...