Computer Science, asked by veerakeshkanna, 6 months ago

Write a program to obtain 5 numbers and print their sum and average

Answers

Answered by vijayghore
1

Answer:

#include<stdio>

using namespace std;

main()

{

    int a[5], sum=0;

    float avg;

    cout<<"Enter 5 numbers";

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

    {

          cin>>a[i];

    }

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

    {

          sum = sum+a[i];

    }

    avg = sum/5.0;

    cout<<"Sum = "sum<<" Average = "avg;

}

Answered by anindyaadhikari13
1

Question:-

Write a program to obtain 5 numbers and print their sum and average.

Program:-

import java.util.*;

class Program

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter 5 numbers.");

double s=0.0, av=0.0;

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

{

double n=sc.nextDouble();

s+=n;

}

av=s/5.0;

System.out.println("Sum is: "+s);

System.out.println("Average is: "+av);

}

}

Similar questions