Sunday, March 10, 2013

C Programming: Basic Arithmetic Operations

Leave a Comment
C Programming: Basic Arithmetic Operations. This program performs basic arithmetic operations like addition, subtraction, multiplication, and division. There are two versions of the program here, the first one is the longer one and the other has more efficiency.
 
#include <stdio.h>
#include <conio.h>

int main()
{
          int x, y, sum, diff, prod, qout;
        
          printf("Enter value for x: ");
          scanf("%d", &x);
          printf("Enter value for y: ");
          scanf("%d", &y);

          sum = x + y;

          diff = x - y;
          prod = x * y;
          qout = x / y;

          printf("\nThe sum of %d and %d is: %d", x, y, sum);

          printf("\nThe difference of %d and %d is: %d", x, y, diff);
          printf("\nThe product of %d and %d is: %d", x, y, prod);
          printf("\nThe qoutient of %d and %d is: %d", x, y, qout);
        
          getch();
          return 0;
}


#include <stdio.h>
#include <conio.h>

int main()
{
          int x, y;
        
          printf("Enter value for x: ");
          scanf("%d", &x);
          printf("Enter value for y: ");
          scanf("%d", &y);

          printf("\nThe sum of %d and %d is: %d", x, y, x + y);

          printf("\nThe difference of %d and %d is: %d", x, y, x - y);
          printf("\nThe product of %d and %d is: %d", x, y, x * y);
          printf("\nThe qoutient of %d and %d is: %d", x, y, x / y);
        
          getch();
          return 0;
}

Here's the output of the program:



0 comments:

Post a Comment