Control Structures(C Program ) Questions and Answers
Explanation:-
Answer: Option C. -> 10 20 21 10The scope of second declaration of i is limited to the block in which it is defined. Outside of the block variable is not recognized.
Explanation:-
Answer: Option A. -> Enter a number:99since this program isn't having any syntax error so program is executed. It is clearly seen that 99 is not divisible by 5. So if statement will not execute and program will terminate.
Explanation:-
Answer: Option B. -> Enter your age: xyz You have lived for 0.00000 secondsWhen 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.
Question 5. What is the output of given program if user enter "xyz" ?
#include
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
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);
}
Explanation:-
Answer: Option C. -> Enter your age: xyz Your age is not validWhen 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.
Explanation:-
Answer: Option C. -> 3 2 1Decrement operator in for loop statement are executed until the condition is true.
So it is executed till "a" not equal to zero and printf statement inside for loop print a value of "a"
Explanation:-
Answer: Option A. -> 1 -1 1Here if statement is executed since we know that printf() function return the number of character print.
Here printf("%d", i) return 2 because it print 1 and newline i.e 2.
And, printf("%d', j) return 3 because it print -1 and newline i.e number of character is 3.
Therefore if statement look like if(2
Explanation:-
Answer: Option B. -> no error no outputthe if is conditional and it checks for expression whether it is zero or non-zero so it doesn't print any data it is clear and it is clearly seen that there is not a single syntax error therefore no complier error.
After compling the program will be executed but there is not a single printf statement so it is executed but will not give any output.