Skip to content

Instantly share code, notes, and snippets.

@najikadri
Created February 22, 2015 18:00
Show Gist options
  • Save najikadri/044177b5187025cfe3fa to your computer and use it in GitHub Desktop.
Save najikadri/044177b5187025cfe3fa to your computer and use it in GitHub Desktop.
simple calculator
#include <stdio.h>
#include <stdlib.h>
int main( void)
{
int a,b,sum,option;
printf("Welcome to C calculator\n");
printf("Choose an option:\n");
printf("add: 1 , Subtract: 2 , Multiply: 3\n");
scanf("%d",&option);
printf("Set first number:\n");
scanf("%d",&a);
printf("Set second number:\n");
scanf("%d",&b);
switch (option) {
case 1: sum = a + b; printf("Result is: %d\n", sum); break;
case 2: sum = a - b;printf("Result is: %d\n", sum); break;
case 3: sum = a * b;printf("Result is: %d\n", sum); break;
default: printf("Wrong option selected!"); break;
}
printf("\nPress Any Key To Continue...\n");
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment