Important Introduction to Programming Short Questions
Chapter: 4
Question 1:
How are multiple variables added together in the program?
Answer:
Multiple variables are added together using the + operator in an expression like TotalAge = age1 + age2 + ... + age10;.
Chapter: 4
Question 2:
What would happen if an expression is used after the >> operator?
Answer:
Using an expression after the >> operator (e.g., cin >> x + y;) is incorrect and will result in a compilation error, as only one variable should be on the right side of >>.
Chapter: 4
Question 3:
How is the final average age displayed to the user?
Answer:
The final average age is displayed using the cout statement: cout << “ The average age of the students is : “ << AverageAge;.
Chapter: 4
Question 4:
What does the program output if the total age is 123?
Answer:
If the total age is 123, the program outputs an average age of 12 because the decimal part (0.3) is truncated.
Chapter: 4
Question 5:
How is the quadratic equation y = ax^2 + bx + c written in C?
Answer:
The quadratic equation is written in C as y = a * x * x + b * x + c;, using the * operator for multiplication.
Chapter: 4
Question 6:
Why are parentheses used in complex expressions in C?
Answer:
Parentheses are used in complex expressions to clarify the order of evaluation and make the expression easier to read and understand.
Chapter: 4
Question 7:
What is the result of the expression x = 2 + 4 * 3 in C?
Answer:
The result of the expression x = 2 + 4 * 3 is 14, because multiplication has higher precedence than addition, so 4 * 3 is evaluated first.
Chapter: 4
Question 8:
What happens if you change the parentheses in x = 2 + (4 * 3)?
Answer:
If you change the parentheses to x = (2 + 4) * 3, the result changes to 18, because addition is performed first, followed by multiplication.
Chapter: 4
Question 9:
How do you extract the last digit of a number in C?
Answer:
You can extract the last digit of a number by using the modulus operator, e.g., digit = number % 10;.
Chapter: 4
Question 10:
What does dividing a number by 10 do in C?
Answer:
Dividing a number by 10 in C removes the last digit of the number, which helps in processing the remaining digits.