Tuesday, February 25, 2020

C Programming if statement predict output MCQs Set-1

C Programming if statement predict output Set-1

Predict output of following C programs based on if statements

Program - 1

#include<stdio.h>
int main()
{
  int score =  100; 
  if ( score != 100 )
    printf("You win ");
  else
    printf("You lose ");

  printf("best prize.");
  return 0;
}
A. You win
B. You lose
C. You lose best prize.
D. You win best prize.

Program - 2

#include<stdio.h>
int main()
{
    int num1=5, num2=4, num3=3;

    if(num1 > num2 && num1 > num3)
    {
         printf("Number1.");
    }
    if(num2 > num1 || num2 > num3)
    {
         printf("Number2.");
    }
    if(num3 > num1 && num3 > num2)
    {
         printf("Number3.");
    }
    return 0;
}
A. Number1.
B. Number2.
C. Number3.
D. Number1.Number2
E. Number1.Number2.Number3

Program - 3

#include<stdio.h>
int main()
{
    int time=0;
   
    if(time < 12)
    {
        printf("Good Morning...");
    }
    printf("Good Day...");
    return 0;
}
A. Good Morning... 
B. Good Day...
C. Good Morning...Good Day...
D. Syntax error

Program - 4

#include<stdio.h>
int main()
{
    int num1=15, num2=10;

    if(num1 > num2)
    {
        printf("Num1 is big..");
    }
    if(num2 > num1)
    {
        printf("Num2 is big..");
    }
    if(num1 = num2)
    {
        printf("Num1 and Num2 are equal.");
    }
    return 0;
}
A. Num1 is big.
B. Num2 is big.
C. Num1 and Num2 are equal.
D. Num1 is big..Num1 and Num2 are equal.
E. Syntax error

Program - 5

#include<stdio.h> 
void main()
{
  int number=0;

  if(number > 0)
     printf("Number is positive.");

  if(number => 0)
     printf("Number is not positive.");
}
A. Number is positive.
B. Number is not positive.
C. Number is positive.Number is not positive.
D. Syntax error

Check your Answer here...

Read more interesting C Programming MCQs here.



No comments:

Post a Comment