Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+1 vote
asked Oct 5, 2019 by jawad

7 Answers

0 votes
answered Oct 5, 2019 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 Oct 9, 2019 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 Oct 12, 2019 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 Oct 12, 2019 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);
}
0 votes
answered Oct 15, 2019 by saiteja (290 points)

#include <stdio.h>

int main()
{
    int a[10],i,sum=0;
    for(i=1;i<=10;i++)
    {
        printf("enter marks of student %d\n",i);
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    float average =sum/10.0;
    
    printf("avgerage marks of 10 students =%.2f\n",average);
    
    return 0;
}

0 votes
answered Oct 16, 2019 by PARTH (140 points)
import java.util.Scanner;

public class Main

{

     

        

public static void main(String[] args)

    {

          int n, d = 0;

          int avg = 0;

          Scanner s = new Scanner(System.in);

          System.out.println("Please enter 10:");

          n = s.nextInt();

          int Array[] = new int[n];

          

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

          {

              Array[i] = s.nextInt();

              d = d + Array[i];

          }

          

          avg = d / n;

          System.out.println("Average:"+avg);        

}

}
0 votes
answered Oct 17, 2019 by Shanthamurthy M S (140 points)
#include <stdio.h>

int main()
{
    int array[10],i,sum;
    printf("enter the 10 students marks\n");
    for(i=0;i<10;i++)
    scanf("%d",&array[i]);
    for(i=0;i<10;i++)
    {
        sum+=array[i];
    }
     printf("the average is %d.%d",sum/10,sum%10);
    return 0;
}
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.
...