Showing posts with label Subtract. Show all posts
Showing posts with label Subtract. Show all posts

How to Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus.

Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus (%)



  1. //Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus (%).
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y;
  7.     cin>>x>>y;
  8.     cout<<"Addition:"<<x+y<<endl;
  9.     cout<<"Subtraction:"<<x-y<<endl;
  10.     cout<<"Multiplication:"<<x*y<<endl;
  11.     cout<<"Integer division:"<<x/y<<endl;
  12.     cout<<"Real division:"<<(float)x/y<<endl;
  13.     cout<<"Modulus"<<x%y;
  14. }

C Program To Do Basic Arithmetic Calculation

How to write a C Program To Do Basic Arithmetic Calculation in C Programming Language ?


  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Factor

Solution For C Program :

/*C Program To Do Basic Arithmetic Calculation.*/


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b,c,ch,num,fact=1,n=0;
char choice='y';
clrscr();
while(choice=='y'||choice=='Y')
  {
  printf("\n:----MENU----:");
  printf("\n[1] :--ADDITION--");
  printf("\n[2] :--SUBTRACTION--");
  printf("\n[3] :--MULTIPLICATION--");
  printf("\n[4] :--DIVISION--");
  printf("\n[5] :--Factorial--");
  printf("\n[6] :--Exit--");
  printf("\nEnter your choice==>");
  scanf("%d",&ch);
  switch(ch)
    {
    case 1:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a+b;
        printf("\nSUM of %d and %d==%d",a,b,c);
        break;
    case 2:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a-b;
        printf("\nSubstraction of %d and %d==%d",a,b,c);
        break;
    case 3:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a*b;
        printf("\nMultiplication of %d and %d==%d",a,b,c);
        break;
    case 4:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a/b;
        printf("\nDivision of %d and %d==%d",a,b,c);
        break;
    case 5:    printf("\nEnter the number for factorial==>");
        scanf("%d",&num);
        n=num;
        while(n>0)
            {
          fact*=n;
          n=n-1 ;
          }
        printf("\nFactorial of %d is==%d",num,fact);
        break;
    case 6:    exit(0);
    default:    printf("\nWrong Choice");
    }
  printf("\n\nDo you want to continue==>");
  fflush(stdin);
  scanf("%c",&choice);
  }
getch();
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program to Add-Subtract Series 5-10+15

How to write a C Program to Add-Subtract Series 5-10+15 in C Programming Language ?


Solution:
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n, sum=0,i,number=5,sign=1;
  5.     for(i=1; i<=9; i++) {
  6.         sum = sum + number*sign;
  7.         number = number + 5;
  8.         sign = sign*(-1);
  9.     }
  10.     printf("%d", sum);
  11. }

C Program to : add/sub/multi/divi works

How to write a C Program to Add, Multiply, Subtract and Divide in C Programming Language ?

Solution:

#include<stdio.h>
/*C Program to Add, Multiply, Subtract and Divide*/