Calculator

#include<stdio.h>
#include<math.h>

void main()
{
    float a,b;
    int x;
    do
    {
        printf("\nChoice:\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Square\n6.Square root\n7.Cube\n8.Logarithm\n9.Exit\n");
        scanf("%d",&x);
        switch(x)
        {
            case 1:
                printf("Enter 2 numbers ");
                scanf("%f%f",&a,&b);
                printf("Addition is %f\n",a+b);
                break;
            case 2:
                printf("Enter 2 numbers ");
                scanf("%f%f",&a,&b);
                printf("Subtraction is %f\n",a-b);
                break;
            case 3:
                printf("Enter 2 numbers ");
                scanf("%f%f",&a,&b);
                printf("Multiplication is %f\n",a*b);
                break;
            case 4:
                printf("Enter 2 numbers ");
                scanf("%f%f",&a,&b);
                printf("Division is %f\n",a/b);
                break;
            case 5:
                printf("Enter a number ");
                scanf("%f",&a);
                printf("Square is %f\n",a*a);
                break;
            case 6:
                printf("Enter a number ");
                scanf("%f",&a);
                printf("Square root is %f\n",sqrt(a));
                break;
            case 7:
                printf("Enter a number ");
                scanf("%f",&a);
                printf("Cube is %f\n",a*a*a);
                break;
            case 8:
                printf("Enter a number ");
                scanf("%f",&a);
                printf("Logarithm is %f\n",log10(a));
                break;
            case 9:
                printf("Exit\n");
                break;
            default:
                printf("Invalid option !!\n");
        }
    }while(x!=9);
}

/*Output

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
1
Enter 2 numbers 1 2
Addition is 3.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
2
Enter 2 numbers 6 5
Subtraction is 1.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
3
Enter 2 numbers 5 6
Multiplication is 30.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
4
Enter 2 numbers 15 3
Division is 5.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
5
Enter a number 3
Square is 9.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
6
Enter a number 9
Square root is 3.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
7
Enter a number 3
Cube is 27.000000

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
8
Enter a number 15
Logarithm is 1.176091

Choice:
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Square
6.Square root
7.Cube
8.Logarithm
9.Exit
9
Exit
*/

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