0

This is a small Program i have written to perform the Basic Operations.
Here is my code for it. Please suggest to improve more.................3

#include <stdio.h>
#include <string.h>
int main()
{
	char operator;
	int num1, num2;
	//char operation[1]={'\0'};
	printf("Enter two numbers and operator to perform calculations!...\n");
	printf("Enter the operator: ");
	scanf("%c",&operator);
	printf("Enter num1: ");
	scanf("%d",&num1);
	printf("Enter num2: ");
	scanf("%d",&num2);

	if (operator=='+')
	{
		printf("Sum is %d\n",num1+num2);
	}
	else if (operator=='-')
	{
		printf("Difference is %d\n",num1-num2);
	}
	else if (operator=='*'){
		printf("Product is %d\n",num1*num2);
	}
	else if(operator=='/'){
		printf("Ratio is %d\n",num1/num2);
	}
	else
		printf("Not given any Operation.");
}

OUTPUT..........


Enter two numbers and operator to perform calculations!...

Enter the operator: +
Enter num1: 12
Enter num2: 13
Sum is 25

Suggest....................:pretty:

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Anil2447
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.