Loading...

Simple Calculator C Program


C Program which take inputs of two number and do all arithematic operation on it:


#include <stdio.h>
main()
{
    float a,b,add,sub,mul,div;

    printf("Enter First no. ");
    scanf("%f", &a);

    printf("Enter Second no. ");
    scanf("%f", &b);

    add= a+b;
    sub= a-b;
    mul= a*b;
    div= a/b;

    printf("\nAddition = %.2f",add);
    printf("\nSubtraction =  %.2f",sub);
    printf("\nMultiplication = %.2f",mul);
    printf("\nDivision = %.2f",div);
}

Also by Simple Method like this: 


#include <stdio.h>
main()
{
    float a,b;

    printf("Enter Two no. ");
    scanf("%f %f",&a,&b);

    printf("\nAddition = %.2f",a+b);
    printf("\nSubtraction =  %.2f",a-b);
    printf("\nMultiplication = %.2f",a*b);
    printf("\nDivision = %.2f",a/b);
}

Also by Making Functions of it:

#include <stdio.h>
void add(float a,float b);
void sub(float a,float b);
void mul(float a,float b);
void div(float a,float b);
main()
{
    float a,b;

    printf("Enter Two no. ");
    scanf("%f %f",&a,&b);

    add(a,b);
    sub(a,b);
    mul(a,b);
    div(a,b);
}
void add(float a,float b)
{
    printf("\nAddition = %.2f",a+b);
}
void sub(float a,float b)
{
    printf("\nSubtraction =  %.2f",a-b);
}
void mul(float a,float b)
{
    printf("\nMultiplication = %.2f",a*b);
}
void div(float a,float b)
{
    printf("\nDivision = %.2f",a/b);
}

Rate this posting:
{[['']]}

0 comments:

Post a Comment

 
TOP