Ticker

6/recent/ticker-posts

Arithmetic operations


  • For addition - 

#include <stdio.h>

int main()
{ int a,b,c;
    printf("Enter the numbers ");
    scanf("%d %d",&a,&b); //Input the numbers
    c=a+b; //performing the operater
    printf("The sum is %d",c); // printing the value 

    return 0;
}


  • For subtraction -
#include <stdio.h>

int main()
{ int a,b,c;
    printf("Enter the numbers ");
    scanf("%d %d",&a,&b); //Input the numbers
    c=a-b; //performing the operater
    printf("The difference is %d",c); // printing the value 

    return 0;
}



  • For multiplication - 
#include <stdio.h>

int main()
{ int a,b,c;
    printf("Enter the numbers ");
    scanf("%d %d",&a,&b); //Input the numbers
    c=a*b; //performing the operater
    printf("The multiplication is %d",c); // printing the value 

    return 0;
}



  • For division - 
 #include <stdio.h>

int main()
{ int a,b,c;
    printf("Enter the numbers ");
    scanf("%d %d",&a,&b); //Input the numbers
    c=a/b; //performing the operater
    printf("The division is %d",c); // printing the value 

    return 0;
}

Alternative approach - 

(using only 2 variables)
 #include <stdio.h>

int main()
{ int a,b;
    printf("Enter the numbers ");
    scanf("%d %d",&a,&b); //Input the numbers
    printf("The sum is %d",a+b); // printing the value 

    return 0;
} 




Post a Comment

0 Comments