c program to sum two numbers code example

Example 1: c program to add two numbers

#include <stdio.h>
int main() {    

    int number1, number2, sum;
    
    printf("Enter two integers: ");
    scanf("%d %d", &number1, &number2);

    // calculating sum
    sum = number1 + number2;      
    
    printf("%d + %d = %d", number1, number2, sum);
    return 0;
}

Example 2: c code to add two numbers

int n,m;
printf("%d",n+m);

Example 3: addition of two numbers in c

int num1,num2;
printf("%d",num1+num2);

Example 4: sum of n natural numbers in c

int addNumbers(int n)
{
    int count, sum = 0;

    for(count=1; count <= n; count++)
    {
        sum = sum + count;
    }
  
    return sum;
}

Tags:

C Example