Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Simple calculator

Posted By: Muhammed Athil     Category: C Programming     Views: 40042

This is a program for beginners in c programming.
This programs helps the beginners to learn about various arithmetic operators and the use of function....

#include<stdio.h>
#include<conio.h>
void main()
{
int add(),sub(),mult(),div();  // declaring four functions
int o;
while(1)  // This loop expression never become false
{
clrscr();
printf("\nEnter the operator\nHINT\n----\n1 for +\n2 for -\n3 for *\n4 for /\n5 for exit");
scanf("%d",&o);
switch(o)
{
case 1:
add();  // calling function
break;
case 2:
sub();  // calling function
break;
case 3:
mult();  // calling function
break;
case 4:
div();   // calling function
break;
case 5:
exit(0);  // This function is used to terminate the program because in while loop exp.(1) is used 

}
}

}
int add() //calling add function
{
int a,b,c;
printf("Enter the numbers");
scanf("%d%d",&a,&b);
c=a+b;
printf("%d + %d = %d",a,b,c);
getch();  
return(0);  //nothing to return

}
int sub()
{
       int a,b,c;
printf("Enter the numbers");
scanf("%d%d",&a,&b);
c=a-b;
printf("%d - %d= %d",a,b,c);
getch();
return(0);
}
int mult()
{
int a,b,c;
printf("Enter the numbers");
scanf("%d%d",&a,&b);
c=a*b;
printf("%d X %d = %d",a,b,c);
getch();
return(0);
}
int div()
{
int a,b,c;
printf("Enter the numbers");
scanf("%d%d",&a,&b);
c=a/b;
printf("%d / %d = %d",a,b,c);
getch();
return(0);
}

  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Simple calculator Or get search suggestion and latest updates.

Muhammed Athil
Muhammed Athil author of Simple calculator is from Calicut, India. Muhammed Athil says

Hello Everyone,I am Muhammed Athil from India

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!