Saturday, June 29, 2013

Write a C program to Add, Subtract, Divide and multiply integers.



#include <stdio.h>
 
void main()
{
   int x, y, add, subtract, multiply;
   float divide;
 
   printf("Enter two integers\n");
   scanf("%d%d", &x, &y);
 
   add        =x + y;
   subtract = x - y;
   multiply = x * y;
   divide     = x / (float) y;   //typecasting
 
   printf("Sum = %d\n",add);
   printf("Difference = %d\n",subtract);
   printf("Multiplication = %d\n",multiply);
   printf("Division = %f\n",divide);
}

No comments:

Post a Comment