Computer Science, asked by UsarshiDas9433, 5 hours ago

Write a program to print the average of 30 and 50​

Answers

Answered by suman7185
0

Answer:

In this example, you will learn to calculate the average of n number of elements entered by the user using arrays.

To understand this example, you should have the knowledge of the following C programming topics:

C while and do...while Loop

C for Loop

C Arrays

Store Numbers and Calculate Average Using Arrays

#include <stdio.h>

int main() {

int n, i;

float num[100], sum = 0.0, avg;

printf("Enter the numbers of elements: ");

scanf("%d", &n);

while (n > 100 || n < 1) {

printf("Error! number should in range of (1 to 100).\n");

printf("Enter the number again: ");

scanf("%d", &n);

}

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

printf("%d. Enter number: ", i + 1);

scanf("%f", &num[i]);

sum += num[i];

}

avg = sum / n;

printf("Average = %.2f", avg);

return 0;

}

Output

Enter the numbers of elements: 6

1. Enter number: 45.3

2. Enter number: 67.5

3. Enter number: -45.6

4. Enter number: 20.34

5. Enter number: 33

6. Enter number: 45.6

Average = 27.69

Explanation:

Please mark me brainliest please

Answered by LaeeqAhmed
0

(swipe right to left for complete ans)

 \color{grey}{\sf \#python \: }

 \sf Number \_one=int(input("First  \: Number"))

 \sf Number \_two=int(input("Second \:  Number"))

 \sf Average=int((Number \_one+Number \_two)/2)

 \sf print(Average)

 \sf{ \purple{in \: our \: case : }}

 \sf{numbers \:are \: 30 \: and \: 50}

 \orange{ \therefore \sf{output \: will \: be \: 40}}

Similar questions