100% prog to make simple calculator with just function call frm main
#include <stdio.h>
float calculate() //function definition
float calculate() //function definition
{
int a,b,choice;
float z; // z will store the output of the math operation
printf("\n enter two integers:");
scanf("%d%d",&a,&b);
printf("\n Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: ");
scanf("%d",&choice);
float z; // z will store the output of the math operation
printf("\n enter two integers:");
scanf("%d%d",&a,&b);
printf("\n Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
z=a+b;
break;
case 2:
z=a-b;
break;
case 3:
z=a*b;
break;
case 4: if (b!=0)
z=a/b;
{
case 1:
z=a+b;
break;
case 2:
z=a-b;
break;
case 3:
z=a*b;
break;
case 4: if (b!=0)
z=a/b;
else
printf("\n avoid dividing with 0");
}
printf("\n math operation of given numbers %d & %d =%f as printed in the called function",a,b,z);
return(z);
}
}
printf("\n math operation of given numbers %d & %d =%f as printed in the called function",a,b,z);
return(z);
}
void main()
{
calculate();
}
ఔట్పుట్ తెరమీద
enter two integers:4 5
Enter 1 for add, 2 for subtract, 3 for multiply and 4 for division: 3
math operation of given numbers 4 & 5 =20.000000 as printed in the called function
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.