OUTPUT (after running):
Enter a number: 153
153 is an Armstrong number
Run2:
Enter a number: 15
15 is not an Armstrong number
Q9.
Write a C program to check whether a given number is binary.
[Hint:
void main( )
{
int r=0,c=0, num, b;
printf(“Enter a number:”);
scanf(“%d”, &num);
b = num;
while(num > 0)
{
if((num % 10 ==0) || (num%10==1))
c++;
r++;
num=num/10;
}
if(c= =r)
printf( “b is a binary number.”;
else
cout << b <<”is not a binary number.”);
}
}
Do'stlaringiz bilan baham: |