C Language

June 5, 2023

How to use arithmetic calculations on integers in C language

program to use arithmetic calculations on integers in C language


#include<stdio.h>
int main()
{
    char op;
    int a,b;
    printf("Enter number,operator and another number : ");
    scanf("%d%c%d",&a,&op,&b);
    switch (op)
    {
    case '+':
        printf("Result=%d\n",a+b);
        break;
    case '-':
    printf("Result=%d\n",a-b);
    break;
    case '*':
    printf("Result=%d\n",a*b);
    break;
    case '/':
    printf("Result=%d\n",a/b);
    break;
    case '%':
    printf("Result=%d\n",a%b);
    break;
    default:
     printf("Enter valid operator\n");
    }
    return 0;
}

output


Enter number,operator and another number : 2+3
Result=5

by : Ajaj Khan

Quick Summary:

program to use arithmetic calculations on integers in C language copy #include&ltstdio.h> int main() { char op; int a,b; printf(“Enter number,operator and another number : “); scanf(“%d%c%d”,&a,&op,&b); switch (op) { case ‘+’: printf(“Result=%d\n”,a+b); break; case ‘-‘: printf(“Result=%d\n”,a-b); break; case ‘*’: printf(“Result=%d\n”,a*b); break; case ‘/’: printf(“Result=%d\n”,a/b); break; case ‘%’: printf(“Result=%d\n”,a%b); break; default: printf(“Enter valid operator\n”); } […]