In the program below, we will learn about how the if statement works. I wanted to calculate square root value of a given number if and only if it is greater than equal to zero. If, however, the value of given number lowers than zero, it always print a zero.
/*To verify the if statement */
#include<stdio.h>
#include<math.h>
int main()
{
float a, b;
printf("Enter the value of a:");
scanf("%f", &a);
if (a>=0)
b=sqrt(a);
printf("\n The square root of %f is: %f\n", a,b);
return(0);
}
/*To verify the if statement */
#include<stdio.h>
#include<math.h>
int main()
{
float a, b;
printf("Enter the value of a:");
scanf("%f", &a);
if (a>=0)
b=sqrt(a);
printf("\n The square root of %f is: %f\n", a,b);
return(0);
}
Comments
Post a Comment