Define variable scope. (02 Marks)b) Write a Statement in C programming to accomplish each of the following:(i) Define the variables x, y , z and the result to be of type int.(ii) Make the program to display text “Enter three integers” to the Screen.(iii)Prompt the user to enter three integers as keyboard input.(iv)Calculate the product of x, y and z and store the value in result.(v) Print “ The product is” followed by the value of the integer variable result.(12 Marks)c) What is the difference between a while loop and a do while loop, show a simple code example (06 Marks)d) Write a program to take input of height for three students and print the height of the tallest
Question
Define variable scope. (02 Marks)b) Write a Statement in C programming to accomplish each of the following:(i) Define the variables x, y , z and the result to be of type int.(ii) Make the program to display text “Enter three integers” to the Screen.(iii)Prompt the user to enter three integers as keyboard input.(iv)Calculate the product of x, y and z and store the value in result.(v) Print “ The product is” followed by the value of the integer variable result.(12 Marks)c) What is the difference between a while loop and a do while loop, show a simple code example (06 Marks)d) Write a program to take input of height for three students and print the height of the tallest
Solution
a) Variable scope refers to the visibility and accessibility of a variable in some particular region of the program. There are two types of variable scope in C programming: local and global. Local variables are those defined within a function or a block, and they can only be accessed within that function or block. Global variables are those defined outside all functions, and they can be accessed by any function throughout the program.
b) Here is how you can accomplish each of the tasks in C programming:
(i)
int x, y, z, result;
(ii)
printf("Enter three integers\n");
(iii)
scanf("%d %d %d", &x, &y, &z);
(iv)
result = x * y * z;
(v)
printf("The product is %d", result);
c) The main difference between a while loop and a do while loop is that in a while loop, the condition is checked before the execution of the loop's body; whereas in a do while loop, the loop's body is executed at least once before the condition is checked. Here are simple examples:
While loop:
int i = 0;
while (i < 5) {
printf("%d ", i);
i++;
}
Do while loop:
int i = 0;
do {
printf("%d ", i);
i++;
} while (i < 5);
d) Here is a program to take the input of height for three students and print the height of the tallest:
#include <stdio.h>
int main() {
int height1, height2, height3, max;
printf("Enter the heights of three students\n");
scanf("%d %d %d", &height1, &height2, &height3);
max = height1;
if (height2 > max)
max = height2;
if (height3 > max)
max = height3;
printf("The tallest height is %d", max);
return 0;
}
Similar Questions
What value does the variable x,y and z have after ALL of the code executes?int x;int y;int z;x = 3;y = 4;z = ++x * y--;Options: Pick one correct answer from belowx = 2, y = 4, z = 12x = 3, y = 3, z = 16x = 4, y = 3, z = 16x = 4, y = 4, z = 12
Describe three different ways of declaring variables in VB (6 Marks
Assume that a, b, and c are three distinct integers. What will X represent after the execution of the following procedure?Step 1. Maintain variable X and Initialize it to 0Step 2. If a < b then go to step 4Step 3. If b < c then store b in X else store c in X and stop the procedure.Step 4. If a < c then store a in X else store c in X
Which of the following would be the variable result value, after the following set of statements?int first = 1;int First = 100;int second = 5;int Second = 50;int result = First * second;5500050050
Which of the following statements is correct about the point in the program marked by the comment WWWW: There are exactly two variables of type int in scope There are exactly two variables of type char in scope There are exactly two variables of type double in scope There is exactly one variable of type double in scope There are no variables of type int in scope
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.