In the program below, we will learn about how the if-else statement works. I
wanted to calculate 4th power of a given number if and only if
it is greater than 2, else if the value of given number
lowers than and equal to 2, it always shows result by adding up with 3.
/*To verify the if else statement */
#include<stdio.h>
#include<math.h>
int main()
{
float a, b;
printf("Enter the value of a:");
scanf("%f", &a);
if (a>2)
b=pow(a,4);
else b=a+3;
printf("\n The calculated value is: %f\n", b);
return(0);
}
/*To verify the if else statement */
#include<stdio.h>
#include<math.h>
int main()
{
float a, b;
printf("Enter the value of a:");
scanf("%f", &a);
if (a>2)
b=pow(a,4);
else b=a+3;
printf("\n The calculated value is: %f\n", b);
return(0);
}
Comments
Post a Comment