Calculator program that performs log, square root, and arithmatic operations

#include<stdio.h>                        //INCLUDING HEADER FILES   
#include<math.h>                        //THIS ONE FOR MATHEMATICAL FUNCTIONS

void add()                            //FUNCTION TO PERFORM ADDITION
{
        float a,b;
    printf("ENTER THE TWO NO. TO BE ADDED::n");
    scanf("%f%f",&a,&b);
    printf("RESULT:: %f+%f=%fn",a,b,a+b);
}

void subtract()                            //FUNCTION TO PERFORM SUBTRACTION
{
        float a,b;
        printf("n ENTER THE NUMBERS (a-b) (a FIRST)::n");
        scanf("%f%f",&a,&b);
        printf("n RESULT:: %f-%f=%fn",a,b,a-b);
}
   
void multiply()                            //FUNCTION TO PERFORM MULTIPLICATION
{
        float a,b;
        printf("n ENTER THE TWO NO. TO BE MULTIPLIED::n");
        scanf("%f%f",&a,&b);
        printf("n RESULT::%f*%f=%fn",a,b,a*b);
}

void divide()                            //FUNCTION TO PERFORM DIVISION
{
        float a,b;
        printf("n ENTER THE NUMBERS (a/b) (a FIRST)::n");
        scanf("%f%f",&a,&b);
    while(b==0)
    {    printf("n DENOMINATOR CAN'T BE ZERO,  RE-ENTER b::");
        scanf("%f",&b);
    }
        printf("n RESULT:: %f/%f=%fn",a,b,a/b);
}

void inverse()                            //FUNCTION TO PERFORM REVERSING
{
        float a;
        printf("n ENTER THE NO. TO BE REVERSED::n");
        scanf("%f",&a);
    while(a==0)
        {       printf("n THE NUMBER CAN'T BE ZERO,  RE-ENTER IT::");
                scanf("%f",&a);
        }
        printf("n RESULT:: 1/%f=%fn",a,1/a);
}

void logbe()                            //FUNCTION TO FIND LOG BASE e
{
        float a;
        printf("n ENTER THE NO. WHOSE Ln IS TO BE CALCULATED::n");
        scanf("%f",&a);
    while(a<=0)
        {       printf("n THE NUMBER SHOULD BE POSITIVE ,  RE-ENTER IT::");
                scanf("%f",&a);
        }
        printf("n RESULT:: ln(%f)=%fn",a,log(a));
}

void logb10()                            //FUNCTION TO FIND LOG BASE 10
{
        float a;
        printf("n ENTER THE NO. WHOSE LOG IS TO BE CALCULATED::n");
        scanf("%f",&a);
    while(a<=0)
        {       printf("n THE NUMBER SHOULD BE POSITIVE ,  RE-ENTER IT::");
                scanf("%f",&a);
        }
        printf("n RESULT:: log(%f)=%fn",a,log(a)/log(10));
}

void sqroot()                            //FUNCTION TO PERFORM SQUQRE ROOT
{
        float a;
        printf("n ENTER THE NO. WHOSE SQUARE ROOT IS TO BE CALCULATED::n");
        scanf("%f",&a);
        while(a<=0)
        {       printf("n THE NUMBER SHOULD BE POSITIVE ,  RE-ENTER IT::");
                scanf("%f",&a);
        }
        printf("n RESULT:: SQUARE ROOT OF %f = %fn",a,log(a)/log(10));
}

main()                                //MAIN() STARTS HERE
{
    int choice;
    do{
    printf("nCALCULATOR MENU::n");
    printf(" 1.  ADDITIONn");
    printf(" 2.  SUBTRACTIONn");
    printf(" 3.  MULTIPLICATIONn");
    printf(" 4.  DIVISIONn");
    printf(" 5.  INVERSEn");
    printf(" 6.  LOG (BASE e)n");
    printf(" 7.  LOG (BASE 10)n");
    printf(" 8.  SQUARE ROOTn");
    printf(" 9.  EXITn");
    printf("nENTER YOUR CHOICE::");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1: add();
            break;
        case 2: subtract();
            break;
        case 3:    multiply();
            break;
        case 4: divide();
            break;
        case 5: inverse();
            break;
        case 6: logbe();
            break;
        case 7: logb10();
                        break;
        case 8: sqroot();
                        break;
        case 9: printf("n BYEn");
            break;
        default:printf("nWRONG CHOICE");
            choice=0;
    }
    }while(!choice);
}   

 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s