c program sum of 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: addition of two numbers in c

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

Example 3: c program to find the sum of given number

# include<stdio.h>
int main
{
int number;
int sum=0;
int remainder;
printf("enter a number\n");
scanf("%d",&number);
for(;number!=0;)
{
remainder=number%10;
sum=sum+remainder;
number=number/10;
}
printf("sum of digits=%d",sum);
}