Computer Science, asked by yoyokesar, 4 days ago

Q. Write a program to input three numbers from the user and print its average.

answer it....​

Answers

Answered by pradeepsharma64290
14

Answer:

To compute the average of three given numbers using C

#include <stdio.h>

#include <conio.h>

int n1,n2,n3;

float avg;

printf("\nENTER THREE NUMBERS: " );

scanf("%d %d %d",&n1,&n2,&n3);

avg=(n1+n2+n3)/3;

printf("\nAVERAGE: %0.2f",avg);

Answered by Anonymous
22

The following program has been written using Python.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third nunber: "))

print("Average: ", round(a+b+c/3, 2))

Note: Average is airthmetic mean.

We've taken three user input and we've stored them as float value.

We're using float() function since user can also enter decimals value and measurements [especially relating to distances] could always have the possibility of being in decimals. If we were to use int() as the data type and a user enters a decimal value, the program would result in an error. To be on the safer side, we use float() as both integers and decimals are accepted.

We then store the final calculation into a separate variable and use it in the next print statement.

Since the final division is also in the possibility of being a really huge number, i.e., having more than 4 decimal places, we use the round() function that rounds the resulting decimal values according to the number we require. In this case, I've limited it to 2 decimal places.

Similar questions