#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int ch;
float a,b,res;
clrscr();
printf(“Enter two numbers:”);
scanf(“%f%f”,&a,&b);
printf(“nMenun1.Additionn2.Subtractionn3.Multiplicationn4.Division”);
printf(“nEnter your choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: res=a+b;
break;
case 2: res=a-b;
break;
case 3: res=a*b;
break;
case 4: res=a/b;
break;
default: printf(“Wrong choice!!nPress any key…”);
getch();
exit(0);
}
printf(“nResult=%f”,res);
getch();
}
how getch(); is coming 2 times is it possible…?
to do division like this
we have to tell that b!=0
as following:
case 4:if (b!=0)
res=a/b;
else
printf("Division not possible");
break;
how remove the decimal in result ?
For that just use integer type instead of float.
Thanks. Why do we add a getch function at the end of the function. We can also freeze output on screen using scanf function. I observed this coding pattern everywhere.
Because in case of getch() the output screen is stopped until we press any key. But in case of scanf() we have to give some input and then press enter to disappear the screen. So getch() is better way to stop output screen.
What mean by Exit(0)
It will terminate program execution.
i ask one question i did’t understand the answer
its saying statement missing
How a program To perform arthemetic operation using arthemetic
I want output for this program
write a program in c++ to input two numbers & perform all arithmetic operations with if else
why are we using the ch and res for
I don’t understand ,when to use %f and when to use %d. please clear my doubts
When you want to print or read float value or value with decimal then use %f. For integer value use %d.
programm is not running
there is error in the program bruh!
result is not running