Tuesday 21 August 2018

Calculator Using C & Function Calling in C Programming | Additaddition & Dvision & Multiplication & Subtraction, Power and Percentage Calculator in one Program Using C |

*Calculator Using C & Function Calling in C Programming*

 Additaddition & Dvision & Multiplication & Subtraction, Power and Percentage Calculator in one Program Using C

How to make a fully functional calculator using C Programming?

***  A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.


#include <stdio.h>
float add(float); /*declaration of Functions */
float sub(float); /*declaration of Functions */
float mut(float);/*declaration of Functions */
float div(float); /*declaration of Functions */
float per(float); /*declaration of Functions */
float power(float); /*declaration of Functions */
float reset(float); /*declaration of Functions */
float result; /*declaration of an Universal float variable*/
main()
{      /* Created By Anupam Dutta aka King Anupam Dutta */
       /* Do not copy the program by close your eyes Read the complete program, analyze the program & then copy*/

          float a;
int fun;
if(result==0.0)
{
printf("\nEnter A Value:\n");
scanf("%f",&a);
}
else
{
a=result;
}
printf("\n\nEnter A Function\n1 for Addition\n2 for Subtraction\n3 for Multiplication\n4 for Division\n5 for Percentage\n6 for to the Power (x^) Function\n7 for Reset\n\n <<Enter Value 0 For HELP!!>> \n");
scanf("%d",&fun);
switch(fun) /*using switch case for calling different function */
{
case 0:
printf("\n Please Contact with Mr. Anupam Dutta \n \n Contacts Details:- \n \n Ph No.- 9163142597 \n Email:- anupamdatta12@gmail.com \n");
getch();
break;
case 1:
add(a);
break;
case 2:
sub(a);
break;
case 3:
mut(a);
break;
case 4:
div(a);
break;
case 5:
per(a);
break;
case 6:
power(a);
break;
case 7:
reset(a);
break;
}
}   /*main function Ends Here*/


float add(float x)
{
float b;
printf("\nEnter A Value:\n");
scanf("%f",&b);
result=x+b;
printf("\nResult:\n %f",result);
main();
}
float sub(float x)
{
float b;
printf("\nEnter A Value:\n");
scanf("%f",&b);
if(x>b)
{
result=x-b;
printf("\nResult:\n %f",result);
main();
}
else
{
result=b-x;
printf("\nResult:\n %f",result);
main();
}
}


float div(float x)
{
float b;
printf("\nEnter A Value:\n");
scanf("%f",&b);
if(x>b)
{
  if(result!=0)
  {
  result=x/b;
printf("\nResult:\n %f",result);
main();
}
else
{
result=1;
result=x/b;
printf("\nResult:\n %f",result);
main();
}
}
else
{
if(result!=0)
{
result=b/x;
printf("\nResult:\n %f",result);
main();
}
else
{
result=1;
result=b/x;
printf("\nResult:\n %f",result);
main();
}
}
}


float mut(float x)
{
float b;
if(result!=0)
{
printf("\nEnter A Value:\n");
scanf("%f",&b);
result=x*b;
printf("\nResult:\n %f",result);
main();
}
else
{
result=1;
printf("\nEnter A Value:\n");
scanf("%f",&b);
result=x*b;
printf("\nResult:\n %f",result);
main();
}
}


float per(float x)
{
if(result==0)
{
result=(x/100);
printf("\nResult:\n %f",result);
main();
}
else
{
float p;
printf("\nPlease Enter a Percent Value:\n");
scanf("%f",&p);
result=(p/100)*result;
printf("\nResult:\n %f",result);
main();
}
}


float power(float x)
{
int i;
float b;
result=x;
float mult=1.0;
printf("\nEnter the Power of the Value (^x):\n");
scanf("%f",&b);
if(b>0)
{
for(i=1;i<=b;i++)
{
mult=mult*x;
}
}
else if(b<0)
{
for(i=b;i<0;i++)
{
mult=mult/x;
}
}
else
{
printf("Enter the Currect Power Value");
}
result=mult;
printf("\n The Value : \n %f ^ %f Will Be = %f \n",x,b,result);
main();
}


float reset(float x)
{
result=0.0;
printf("Result = %f",result);
main();
}