C program to perform arithmetic operations

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
    int a=5,b=20;
    int add,sub,mul,div,mod;

    //Addition
    add=a+b;
    printf("a + b =%d\n",add);

    //Subtraction
    sub=a-b;
    printf("a - b =%d\n",sub);

    //Multiplication
    mul=a*b;
    printf("a * b =%d\n",mul);

    //Division
    div=a+b;
    printf("a / b =%d\n",div);

    //Mod
    mod=a%b;
    printf("a mod b =%d",mod);
}

OUTPUT:

a + b =25
a - b =-15
a * b =100
a / b =25
a mod b =5

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.