Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sukanta Biswas , Software Developer (2019-present)

Name: Anonymous 2021-03-22 22:43

Hello there. I made a C program for the Calculator which can calculate Addition, Subtraction, Multiplication, Division, finding Square,Cube, Percentage of the numbers.

It may be little bit tricky for the beginners since it’s a big program but it will give you the knowledge of:

function call,
recursion,
if-else statement
switch-case

Here users are allowed to give their choice to calculator to perform any of the above task. I think its a cool program.

Hope it helps! Thanks. Happy coding. Don’t forget to upvote if it help.
#include<stdio.h>
int add(int x, int y)
{
int c;
c=x+y;
printf("\nThe sum is=%d\n\n",c);
}
int sub(int d, int e)
{
int f;
f=d-e;
printf("\nThe subtraction is=%d\n\n",f);
}
int mult(int x, int y)
{
int i;
i=x*y;
printf("\nThe multiplication is=%d\n\n",i);
}
double div(double x, double y)
{
double m;
m=x/y;
printf("\nDivison is=%.3lf\n\n",m);
}
int sq(int x, int y)
{
int sqr1,sqr2;
sqr1=x*x;
sqr2=y*y;
printf("\nSquare of %d is=%d\n",x,sqr1);
printf("\nSquare of %d is=%d\n\n",y,sqr2);
}
int cube(int x, int y)
{
int cub1,cub2;
cub1=x*x*x;
cub2=y*y*y;
printf("\nCube of %d is=%d\n",x,cub1);
printf("\nCube of %d is=%d\n\n",y,cub2);
}
int percentage(int x,int y)
{
float per1,per2;
per1=100*x/y;
per2=100*y/x;
printf("\n%d is %.3f %c of %d\n",x,per1,37,y);//% sign using ASCII code 37
printf("\n%d is %.3f %% of %d\n\n",y,per2,x);//% sign by traditional %% code
}

int main()
{
int x,y,options=0;
printf("Enter numbers one by one:\n");
scanf("%d%d",&x,&y);
printf("\nWelcome! What do you want to perform your calculator?\n");
printf("\n1.For Addition enter 1\n\n2.For Subtraction enter 2\n");
printf("\n3.For Multiplication enter 3\n\n4.For Division enter 4\n");
printf("\n5.To find Square of the numbers enter 5\n\n6.To find Cube of the numbers enter 6\n");
printf("\n7.For Percentage of both numbers enter 7\n");
printf("\nEnter your choice:");
scanf("%d",&options);
switch(options)
{
case 1:
add(x,y);
break;
case 2:
sub(x,y);
break;
case 3:
mult(x,y);
break;
case 4:
div(x,y);
break;
case 5:
sq(x,y);
break;
case 6:
cube(x,y);
break;
case 7:
percentage(x,y);
break;
default:
printf("\n\nPlease enter number from the given list!\n");
main();
}
}

Name: Anonymous 2021-03-22 22:54

Saai Natha
, studied Science and Mathematics & 10th Class in India at Indus Universal School

The Simplest Code To Make A Calculator Is..

#include<stdio.h>

#include<math.h>

To Make A Normal Calculator Follow This Code…….

#include<stdio.h>

main()

{

int a,b,ans;

char op;

printf(“Enter Operator: “);

scanf(“%c”,&op);

printf(“Enter Value Of ‘a’: “);

scanf(“%d”,&a);

printf(“Enter Value Of ‘b’: “);

switch(op)

{

case ‘+’:

ans=a+b;

printf(“RESULT: %d”,ans);

break;

case ‘-’:

ans=a-b;

printf(“RESULT: %d”,ans);

break;

case ‘*’:

ans=a*b;

printf(“RESULT: %d”,ans);

break;

case ‘/’:

printf(“RESULT: %d”,ans);

break;

default:

printf(“Operator Not Found………..”);

break;

}

return 0;

}

To Make The Calculator More User Friendly Follow This Code………

#include<stdio.h>

#include<math.h>

#include<conio.h>

#include<stdlib.h>

main()

{

char s;

float a,b,ans;

printf("Enter: ");

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

switch(s)

{

case '+':

ans=a+b;

printf("RESULT: %f",ans);

break;

case '-':

ans=a-b;

printf("RESULT: %f",ans);

break;

case '*':

ans=a*b;

printf("RESULT: %f",ans);

break;

case '/':

ans=a/b;

printf("RESULT: %f",ans);

break;

default:

printf("Operator Was Not Found.......");

break;

}

getch();

}

Name: Anonymous 2021-03-22 22:59

Paritosh Kr Rakesh
, C.E.O and Co-founder at CarbL (2018-present)

Following is the code for creating a simple calculator using a user controlled loop structure and branching using switch statements, and this program not close or it does not stop the operation until the user wants it to do so, i.e if you want to use it continuously or want to use different operations on the same two numbers, it allows you to do so. After every operation on the same two number it will ask you to enter another operand for the same two numbers. And if you want to change the numbers, you can enter Q or N.

#include <stdio.h>
main()
{
int a, b;
typedef char String; /* renaming our char datatype to String */
String operator; /* here operator is '+' , '-' , '*' , '/' that we will use in calculations */
typedef int bool; /* renaming our int data type to boolean */
bool condition = 1; /* condition = 1 means while condition = true */
/* beginning of the program */
while(condition) /* while(condition = true) */
{
printf("Enter first number: ");
scanf("%d",&a);
printf("\n");
printf("Enter second number: ");
scanf("%d",&b);
printf("Now enter commands to use on these numbers. \n");
printf("You can use '+' , '-' , '*', '/' \n");
printf("You can use Q or N to quit \n");
do /* an inner loop */
{
printf(">>"); /* prompt use for the command */
scanf("%c", &operator);
switch(operator)
{
case '*' : printf("%d * %d = %d \n",a,b, a*b);
break;
case '+' : printf("%d + %d = %d \n",a,b, a+b);
break;
case '-' : printf("%d - %d = %d \n",a,b, a-b);
break;
case '/' : if(b == 0)
printf("cannot divide by 0\n");
else
printf("%d / %d = %d \n",a,b, a/b);
break;
case 'Q' : condition = 0; break; /*now condition = false */
}
if(operator == 'Q' || operator == 'N') /*come out of the do loop */
break;
}while(1);
}
printf("Finished....");
}

Name: Anonymous 2021-03-22 23:58

Name: Anonymous 2021-03-23 4:09

Hello sirs, please don't use this new unsafe language C there is a proven industry solution already
https://github.com/azac/cobol-on-wheelchair

Name: Anonymous 2021-03-23 10:39

>>4
I needed a skeleton of infix parser, but today it is bit hard to find one. In fact, it is hard to find any good code - it gets drowned in all the nonsense.

Name: Anonymous 2021-03-24 0:29

>>5

Wow, they made it all the way up to 8 issues before getting derailed by inclusive terminology debates.

Name: Anonymous 2021-03-24 14:37

>>7
Pro-tip: they can't cancel you if you are not using github.

Name: Anonymous 2021-03-24 15:25

Name: Anonymous 2021-03-24 21:20

>>9
uses a communist site run a by Cuban nigger
complains about political correctness

Name: Anonymous 2021-03-24 21:26

>>10
african american*

Name: Anonymous 2021-03-25 1:29

>>12
Afro-cubanx

Name: Anonymous 2021-03-25 4:47

I went to a Cubanx bar once, the Mojitos were excellent; the shemales, not so good.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List