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

I need a solution for this problem, I prefer to get the answer using printf and

ID: 3871836 • Letter: I

Question

I need a solution for this problem, I prefer to get the answer using printf and scanf not cout and cin.

Please, Answer the three listing

Program: C Compiler

1. What will be the output of the following programs. Also, (a) Explain the output and (b) If an error occurred while executing the given program, analyse the error and propose the solution (while presenting present the error and your proposed correction side by side). Listing 1: Question 1 # include # include main() int a = 300, b, c; if (a 400) b 300; c = 200; printf(" %d %d", b, c); Listing 2: Question 1 # include # include main () int a, b; scanf-s("%d %d", a, b); if (a > b); printf("If Life is a Game" else printf ("I shall play it cool!!")

Explanation / Answer

Hey,

hope this helps you .

#include<stdio.h>
#include<math.h>

void main() {
int a=300,b,c;
if(a>=400){
b=300;
a=200;
printf(" %d %d",b,c);
}
} // and the output of this program will be nothing since the if condition in the program is false. Hence no action will take place.

Here in listing 2, you have many bugs. Starting with the return type again, ur main function need to have a return type. Give it any and return that before the last brace. Second, the usage of scanf_s function is wrong, u can either use scanf or any other version of the scanf function. Third, u have applied semicolon after if statement that actually ends the if statement there only hence the last part of else is treated without if. The more modified version of ur code can be:

#include<stdio.h>
#include<math.h>

void main() {
int a,b;
scanf("%d %d",&a,&b);
if(a>b)
{
printf("If life is a game");
}
else
printf("I'll shall play it cool!..");
} //now according to ur input of variable a & b , u will see ur result.

Listing 3 has the maximum bugs. First, the second include statement, the keyword "include" is mispelled, Second, main function doesnt have return type. Third, the declaration of variables is wrong , there needs to be a comma between a and b or no space. Fourth, implementation of function scanf_s is not correct, instead use scanf or other function, Fifth, usage of semicolon just after if statement is not correct. Same is with else also. Sixth, there should no space between printf ( not print f) and the printf statement in the block of else needs to be terminated with semicolon. Ur code can be modified to working as follows:

#include<stdio.h>
#include<math.h>

void main() {
float a ,b,c;
scanf("%f %f",&a,&b);
printf("%f",c);
if(a>b)
{
if(a=c)
printf("If life is a game");
}
else
printf("I'll shall play it cool!..");   
}

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