?
What is the output of given program if user enter "xyz" ?
What is the output of given program if user enter "xyz" ?
#include<stdio.h>
void main()
{
float age, AgeInSeconds;
int value;
printf("Enter your age:");
value=scanf("%f", &age);
if(value==0){
printf("\\nYour age is not valid");
}
AgeInSeconds = 365 * 24 * 60 * 60 * age;
printf("\\n You have lived for %f seconds", AgeInSeconds);
}
#include<stdio.h>
void main()
{
float age, AgeInSeconds;
int value;
printf("Enter your age:");
value=scanf("%f", &age);
if(value==0){
printf("\\nYour age is not valid");
}
AgeInSeconds = 365 * 24 * 60 * 60 * age;
printf("\\n You have lived for %f seconds", AgeInSeconds);
}
Answer & Solution
Correct Answer:
Option
C
When we give scanf() a "%f" format string, that means "We want you to try and get us a floating point number. When we provide input like 'xyz', it's not going to match anything, because 'xyz' is not a valid floating-point number.
Join the Discussion
Login to post a comment or share your explanation.
LoginEnter your age: xyz
Your age is not valid
You have lived for 0.000000 seconds
If you check the option A it have an extra space between age and colon.