Turn Desktop View Off
You are here:   HomeC Programming (Theory)Basic Of C Prog.Write a C program to console menu: calculation.
by Dinesh Thakur Category: Basic Of C Programming

 

 

#include<stdlib.h>

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char command[80], temp[80];
int i, j;
for(; ;)
{
printf("Operation: add, subtract, divide and multiply? \n”);
printf("Enter the whole word \n”);
gets(command);
if(!strcmp(command, "quit"))
break;
printf("Enter the first number: ");
gets(temp);
i = atoi(temp);
printf("Enter the second number: ");
gets(temp);
j = atoi(temp);
if(!strcmp(command, "add"))
printf("%d\n", i + j);
else if(!strcmp(command, "subtract"))
printf("%d\n", i - j);
else if(!strcmp(command, "divide"))
{
if(j)
printf("%d\n", i / j);
}
else if(!strcmp(command, "multiply"))
printf("%d\n", i * j);
else
printf("Unknown command. \n");
}
getch();
}
 
OUTPUT:
 
Operation: add, subtract, divide and multiply?
enter the whole word
subtract
Enter the first number: 512
Enter the second number: 412
100


Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article