1) What is the first step in problem-solving? A) Writing code B) Debugging C) Understanding the problem D) Optimizing the solution Answer: C 2) Which of these is not a step in the problem-solving process? A) Algorithm development B) Problem analysis C) Random guessing D) Testing and debugging Answer: C 3) What is an algorithm? A) A high-level programming language B) A step-by-step procedure to solve a problem C) A flowchart D) A data structure Answer: B 4) Which of these is the simplest data structure for representing a sequence of elements? A) Dictionary B) List C) Set D) Tuple Answer: B 5) What does a flowchart represent? A) Errors in a program B) A graphical representation of an algorithm C) The final solution to a problem D) A set of Python modules Answer: B 6) What is pseudocode? A) Code written in Python B) Fake code written for fun C) An informal high-level description of an algorithm D) A tool for testing code Answer: C 7) Which of the following tools is NOT commonly used in pr...
C program to check if a number is binary or not
int isBinary(int num) {
while (num != 0) {
if (num % 10 > 1) {
return 0;
}
num /= 10;
}
return 1;
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (isBinary(num)) {
printf("%d is a binary number.\n", num);
} else {
printf("%d is not a binary number.\n", num);
}
return 0;
}
Explanation :
This program defines a function isBinary that takes an integer num as input and returns 1 if num is a binary number, and 0 otherwise. The function checks each digit of the number by dividing it by 10 and checking if the remainder is greater than 1. If any digit is greater than 1, the function returns 0, indicating that num is not a binary number. If all digits are less than or equal to 1, the function returns 1, indicating that num is a binary number.
In the main function, the program prompts the user to enter a number and then calls the isBinary function to check if the number is binary. Depending on the result, the program prints a message to the console indicating whether the number is binary or not.
Sample output:
Here's an example output of the program for the input of the number 10101010:
Enter a number: 10101010
10101010 is a binary number.
And here's an example output of the program for the input of the number 1234:
Enter a number: 1234
1234 is not a binary number.