Simple Calculator

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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