Multiple choice

Which of the following statements about the above program is correct if we enter the number as 1111?

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

int main()

{

long n;

int x,y=0,p=0;

printf("enter number");

scanf(%d,&n);

while(n!=0)

   {

x=n%10;

if(x>1 || x<0)

      {

printf("invalid" );

exit(1);

      }

y=y+x*pow(2,p);

n=n/10;

p++;

   }

printf("answer is %d",y);

getch();

}

  1. Program will find the sum of digits.

  2. Program will find the number of digits.

  3. Invalid

  4. Program will run infinite times.

  5. There will be error in the program.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This option is correct.