C program that calculates the sum and average of three numbers

C program that calculates the sum and average of three numbers:

C programming tutorial

Code:-

#include <stdio.h>

int main() {

  float num1, num2, num3, sum, average;


  // Get user input for the three numbers

  printf("Enter three numbers: ");

  scanf("%f %f %f", &num1, &num2, &num3);


  // Calculate the sum of the three numbers

  sum = num1 + num2 + num3;


  // Calculate the average of the three numbers

  average = sum / 3;


  // Print the sum and average of the three numbers

  printf("Sum = %.2f\n", sum);

  printf("Average = %.2f\n", average);


  return 0;

}


Explaination about this code:-

In this program, we declare five variables: num1, num2, num3, sum, and average. We then use the scanf function to get user input for the three numbers, and store them in the num1, num2, and num3 variables. We then calculate the sum of the three numbers by adding them together and storing the result in the sum variable. Finally, we calculate the average of the three numbers by dividing the sum by 3, and storing the result in the average variable.


We then use the printf function to print out the values of the sum and average variables, using the %f format specifier to print out floating-point values with two decimal places.


When you run this program and enter three numbers, it will calculate the sum and average of those numbers and print out the results.


Conclusion:

We are about in this post that calculate the sum of 3 numbers and you know other program like arithmetic Operators , basic concept of c language, c language operators etc.

I hope you are helpful in this post and any questions so tells the comment box .

Thankyou 

Post a Comment

0 Comments