Q. – Write a C program to find the sum of given two numbers.
Ans:- Two numbers, says a and b, are given (input) and the result sum = a+b of two numbers are to be calculated.
/* Arithmetic Operators Addition */
#include <stdio.h>
int main()
{
int a, b, sum;
scanf("%d %d", &a, &b);
sum = a+b;
printf("%d", sum);
return 0;
}
User- Friendly Program
/* Arithmetic Operators Addition – User friendly program */
#include<stdio.h>
int main()
{
int a, b, sum;
printf("\n Enter Value to A: ");
scanf("%d", &a);
printf("\n Enter Value to B: ");
scanf("%d", &b);
sum = a+b;
printf("\n SUM = %d", sum);
return 0;
}
No comments