You are on page 1of 2

/* C programming source code to add and display the sum of two integers entered

by user using two variables only. */


#include <stdio.h>
int main( )
{
int num1, num2, sum;
printf("Enter a two integers: ");
scanf("%d %d",&num1,&num2);
num1=num1+num2; /* Adds variables num1 and num2 and stores it in num1 */
printf("Sum: %d",num1); /* Displays value of num1 */
return 0;
}
/*C program to multiply and display the product of two floating point numbers
entered by user. */
#include <stdio.h>
int main( )
{
float num1, num2, product;
printf("Enter two numbers: ");
scanf("%f %f",&num1,&num2);
/* Stores the two floating point numbers
entered by user in variable num1 and num2 respectively */
product = num1*num2; /* Performs multiplication and stores it */
printf("Product: %f",product);
return 0;
}

REFERENCE
http://www.programiz.com/c-programming/examples

C program to add two numbers


#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter two numbers to add\n");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %d\n",c);
}

return 0;

C program to perform addition, subtraction, multiplication and division


#include <stdio.h>
int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add = first + second;
subtract = first - second;
multiply = first * second;
divide = first / (float)second;

//typecasting

printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Division = %.2f\n",divide);
return 0;
}

REFERENCE
http://www.programmingsimplified.com/c-program-add-two-numbers
http://www.programmingsimplified.com/c/program/addition-subtractionmultiplication-and-division

You might also like