0% found this document useful (0 votes)
76 views3 pages

Simple Calculator

The document contains the code for a simple calculator program that allows a user to input two numbers and select from four mathematical operations (addition, subtraction, multiplication, division) to be performed on the numbers. The program displays the selected operation and result. It uses scanf to input the numbers, stores the results of each operation, and uses a switch statement to output the selected operation result.

Uploaded by

amani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views3 pages

Simple Calculator

The document contains the code for a simple calculator program that allows a user to input two numbers and select from four mathematical operations (addition, subtraction, multiplication, division) to be performed on the numbers. The program displays the selected operation and result. It uses scanf to input the numbers, stores the results of each operation, and uses a switch statement to output the selected operation result.

Uploaded by

amani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Simple calculator

#include<stdio.h>
void main()
{
int a,b,ad,sb,ml,dv,e;
printf("\tWelcome to our simple calculator\n");
printf("enter number 1\n");
scanf("%d",&a);
printf("enter number 2\n");
scanf("%d",&b);
printf("\t\tMathematical operation");
printf("\n..............................................");
printf("\n1- Addition");
printf("\n2- Subtraction");
printf("\n3- Multiplication");
printf("\n4- Division");
printf("\n..............................................");
printf("\n Enter number of your preference:");

ad=a+b;
sb=a-b;
ml=a*b;
dv=a/b;

scanf("%d",&e);
switch(e)
{
case 1: printf("\n Addition is %d\n",ad);
break;
case 2:
printf("\n Subtraction is %d\n",sb);
break;
case 3: printf("\n Multiplication is%d\n",ml);
break;
case 4: printf("\n Division is %d\n",dv);
break;
default: printf("\n Incorrect input\n");
break;
}
}
Program to find even and odd
#include<stdio.h>
int main()
{
int a;
printf ("enter the value of the number");
scanf("%d",&a);
if (a%2==0)
{
printf("even number");

}
else
{
printf("odd number");
}
return 0;}

program to find the absolute value of a function


#include<stdio.h>
int main()
{
int a,b;
printf("enter the value of number");
scanf("%d",&a);
b=-a;
if(a<0)
{
printf("the absolute value of the number is %d",b);
}
else
{
printf("the absolute value of the number is %d",a);
}
return 0;}
Program to find the smallest of three numbers
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the values of the number");
printf("\nenter number 1=");
scanf("\n%d",&a);
printf("\nenter number 2=");
scanf("\n%d",&b);
printf("\nenter number 3=");
scanf("\n%d",&c);
if (a<b)
{
if (a<c)
{
printf("%d is the smallest",a);
}
else
{
printf("%d is the smallest",c);
}
}
else
{
if (b<c)
{
printf("%d is the smallest",b);
}
else
{
printf("%d is the smallest",c);
}
}
return 0;}

You might also like