C programming Calculator

 #include<stdio.h>

#include<conio.h>

#include<math.h>

int main()

{

while(1)

{

int x;

void add(void);

void multiply(void);

void substruction(void);

void division(void);

void sqrt(void);

void odd_even(void);

void prime_composite(void);

void avg(void);

void no_of_digits(void);

void reverse(void);

void sum_of_digits_of_number(void);

void trignometry(void);

void abundant_number(void);

printf("1. Addition\n");

printf("2. Multiplication\n");

printf("3. Substruction\n");

printf("4. Division\n");

printf("5. Square\n");

printf("6. Odd or Even\n");

printf("7. Prime or Composite\n");

printf("8. Average\n");

printf("9. Total number of digits\n");

printf("10. Reverse a number\n");

printf("11. Sum of Digits of Number\n");

printf("12. Trignometry\n");

printf("13. Checking whether the number is Abundant\n");

printf("Select the choice:\n");

scanf("%d\n",&x);

switch(x)

{

case 1:

add();

break;

case 2:

    multiply();

break;

case 3:

    substruction();

break;

case 4:

    division();

break;

case 5:

    sqrt();

break;

case 6:

    odd_even();

break;

case 7:

    prime_composite();

break;

case 8:

    avg();

break;

case 9:

    no_of_digits();

break;

case 10:

    reverse();

break;

case 11:

    sum_of_digits_of_number();

break;

case 12:

    trignometry();

break;

case 13:

    abundant_number();

break; 

}

    

}

   return 0;

}

void add()

{

float a,b,c;

printf("Enter two numbers:");

scanf("%f + %f",&a,&b);

c=a+b;

printf("The sum is %f\n",c);

}

void multiply()

{

float a,b;

printf("Enter two numbers:");

scanf("%f * %f",&a,&b);

printf("The multiplication is %f",a*b);

}

void substruction()

{

float a,b;

printf("Enter two numbers:");

scanf("%f - %f",&a,&b);

printf("The substruction is %f:",a-b);

}

void division()

{

float a,b,c;

printf("Enter two numbers:");

scanf("%f / %f",&a,&b);

c=a/b;

printf("The division is %f:",c);

}

void sqrt()

{

float a;

printf("Enter a number:");

scanf("%f",&a);

printf("The Squrae is %f",a*a);

}

void odd_even()

{

int a;

printf("Enter a number:");

scanf("%d",&a);

if (a%2==0)

{

printf("The number is Even");

}

else

{

printf("The nnumber is odd");

    }

}

void prime_composite()

{

int i,a;

printf("Enter a number:");

scanf("%d",&a);

for(i=2;i<a;i++)

{

if(a%i!=0)

{

printf("prime number");

break;

}

else

{

printf("Composite number");

break;

}

}

}

void avg()

{

float a,b;

printf("Enter two numbers:");

scanf("%f %f",&a,&b);

printf("The average is %f",(a+b)/2);

}

void no_of_digits()

{

int num,digits;

printf("Enter a number:");

scanf("%d",&num);

digits=log10(num)+1;

printf("Total digits are %d",digits);

}

void reverse()

{

int n,num=0;

printf("Enter a number:",n);

scanf("%d",&n);

while(n!=0)

{

num=(num*10)+(n%10);

n/=10;

}

printf("%d",num);

}

void sum_of_digits_of_number()

{

int n,sum=0;

printf("Enter a number:",n);

scanf("%d",&n);

while(n!=0)

{

sum+=(n%10);

n/=10;

}

printf("%d",sum);

}

void trignometry()

{

int x;

float a,b;

printf("1. Sin\n");

printf("2. Cos\n");

printf("3. Tan\n");

printf("4. Cot\n");

printf("5. Sec\n");

printf("6. Cosec\n");

printf("Enter your choice:");

scanf("%d",&x);

printf("Enter a number:");

scanf("%f",&a);

switch(x)

{

case 1:

b=sin(a);

printf("The solution is %f",b);

break;

case 2:

b=cos(a);

printf("The solution is %f",b);

break;

case 3:

b=tan(a);

printf("The solution is %f",b);

break;

case 4:

b=1/tan(a);

printf("The solution is %f",b);

break;

case 5:

b=1/cos(a);

printf("The solution is %f",b);

break;

case 6:

b=1/sin(a);

printf("The solution is %f",b);

break;

    }

}

void abundant_number()

{

    {

       int number,sum=0,c;

   printf("Enter a number:"); 

      scanf("%d",&number);

     for(c = 1 ; c < number ; c++)

     {

           if(number % c == 0)

               sum = sum + c;

     }

     if(sum > number)

           printf("Abundant Number");

     else

           printf("Not a Abundant number");

    }

}

Comments