Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Show the output for the following code blocks: int x=3, y=4, z=5; 1. if (x==3) p

ID: 3695390 • Letter: S

Question

Show the output for the following code blocks:
int x=3, y=4, z=5;

1. if (x==3)
printf (“Hi”);

2. if (x==4)
printf(“Hi”);
else
printf(“Bye”);

3. if (x <= z)
{
printf(“Hi…”);
printf(“How’s it going?”);
}
else
{
printf(“Bye…”);
printf(“See you later!”);
}

4. if (x == 0)
printf(“x is equal to 0”);
else if (x == 1)
printf(“x is equal to 1”);
else if (x == 2)
printf(“x is equal to 2”);
else
printf(“x is not equal to 0, 1, or 2”);
double x = 75.0, y=85.0, z=95.0;

5. Write code that uses an if-statement to test if x is less than y, if it is, print a message “x is less than y”.

6. Write code that uses an if-else statement to test if x is not equal to z, if so, print 2 messages: “x is not equal to z” and “maybe x is equal to y?”, else, print “x is not equal to z”.

7. Write code that uses an if-else-if statement to test if z is less than 80.0, if so, print 2 messages: “z is less than 80.0” and “good job”, else test if z is less than 90.0, if so, print 2 messages: “z is less than 90.0” and “good job”, else test if z is less than 100.0, if so, print 2 messages: “z is less than 100.0” and “good job”, else print a message “z is greater than or equal to 100”.

Show the output for the following code block:
8. int i = 0, stopValue = 5;
while (i < stopValue)
{
printf(“This is loop number %d”, i);
i = i + 1;
}

9. Write a while loop that will print “Hello there!” 7 times to the screen:

10. Write a for loop that will print “Hello there!” 12 times to the screen:

Explanation / Answer

1. if condition is true, so it will print Hi
Hi

2. if condition is false, so it will execute else part.
Bye

3.Here if condition is true, so it will execute if part.
Hi
How's it going?

4.
X is not equal to 0, 1, or 2

5.Here if condition and else if condition and one more else if conditions are false, so it will execute elase part.
#include<stdio.h>
#include<conio.h>
main()
{
double x = 75.0 , y = 85.0 , z = 95.0;
if(x<y)
{
printf("x is less than y");
}
getch();
}

6.
#include<stdio.h>
#include<conio.h>
main()
{
double x = 75.0 , y = 85.0 , z = 95.0;
if(x != z)
{
printf("x is not equal to z" and "maybe x is equal to y?");
}
elase
{
printf("x is not equal to z");
}
getch();
}

7.
#include<stdio.h>
#include<conio.h>
main()
{
double x = 75.0 , y = 85.0 , z = 95.0;
if(z<80.0)
{
printf("z is less than 80.0" and " good job");
}
else if(z<90.0)
{
printf("z is less than 90.0" and " good job");
}
else if(z<100.0)
{
printf("z is less than 100.0" and " good job")
}
else
{
printf("z is greater than or equal to 100");
}
getch();
}

output:
z is less than 100.0
good job

8.
output:
This is loop number 0
This is loop number 1
This is loop number 2
This is loop number 3
This is loop number 4

9.
int i = 1;
while(i <= 7)
{
printf(" Hello there!");
i = i + 1;
}

10.
int i;
for(i = 1 ; i<=12 ; i++)
{
printf(" Hello there!");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote