Write a C program to calculate the sum of three numbers

Description: Take three numbers as input and print their sum.

Hint:

  • Read the numbers with scanf() and add them with the + operator.

C program to calculate the sum of three numbers

#include <stdio.h>

int main(void) {
    int a, b, c;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    printf("Sum = %d\n", a + b + c);
    return 0;
}

Output:

Output of the above program is

Enter three numbers: 10 20 30
Sum = 60

How it works

  • The three numbers are stored in a, b and c.
  • The expression a + b + c is calculated and printed.

Learn more about the similar topics:
Tutorials
C Keywords
C Variables
C Data Types
C Constants
C printf and scanf
C Escape Sequences
C Format Specifiers
Exercises & Assignments
Write a C program to swap the values of two variables using a third variable
Write a C program to print words using spacing and new line characters
Write a C program to get the salary from the user and print it
Write a C program to find the size of int, float, long, double and char
Write a C program to get the marks of 5 subjects and find the total and average
Write a C program to calculate the perimeter of a rectangle
Write a C program to convert minutes into hours and minutes
Interview Questions & Answers
What is the difference between a variable and a constant in C?
What are the data types in C?
What is the difference between = and == in C?
What is the difference between ++i and i++ in C?
What is the use of the sizeof operator in C?
How to swap two numbers in C?