1. Study (write, compile, and run/test) the following two programs. ++++++++++++
ID: 3880890 • Letter: 1
Question
1. Study (write, compile, and run/test) the following two programs.
++++++++++++++++++++++++++++++++++++++++++++++++++
// Here goes brief description of the program - program 1 // Author:
// Date:
// CSCI3100A-Spring2018-LA1
++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main() {
int c;
}
return 0; }
//++++++++++++++++++++++++++++++++++++++++++++++++++
// Here goes brief description of the program - program 2 // Author:
// Date:
// CSCI3100A-Spring2018-LA1
//++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main() {
int c;
}
return 0;
}
• What do the programs do?
• Explain the differences between these two programs
• Compare the following two statements and describe its differences: c = getchar() != EOF; and c = (getchar() != EOF);
2. Study (write, compile, and run/test) the following two programs.
//++++++++++++++++++++++++++++++++++++++++++++++++++
// Here goes brief description of the program - program 3 // Author:
// Date:
// CSCI3100A-Spring2018-LA1
//++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main() {
long nc;
return 0; }
//++++++++++++++++++++++++++++++++++++++++++++++++++
// Here goes brief description of the program - program 4
// Author:
// Date:
// CSCI3100A-Spring2018-LA1
//++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main() {
double nc;
return 0; }
• What do the programs do?
• Explain the differences between these two programs
• In program 4, why the body of the for loop is empty? Is this an error? Explain.
3. Study (write, compile, and run/test) the following two programs.
//++++++++++++++++++++++++++++++++++++++++++++++++++
// Here goes brief description of the program - program 5
// Author:
// Date:
// CSCI3100A-Spring2018-LA1
//++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main() {
int c, nl;
return 0; }
1 //++++++++++++++++++++++++++++++++++++++++++++++++++
2 //
3 //
4 //
5 //
6 //++++++++++++++++++++++++++++++++++++++++++++++++++
7 #include <stdio.h>
Here goes brief description of the program - program 6 Author:
Date:
CSCI3100A-Spring2018-LA1
8
9 #define IN 1
10 #define OUT 0
11
12 int main()
13 {
14 int c, nl, nw, nc, state;
15
16 state = OUT;
17 nl=nw=nc=0;
18 while 19
20
21
22 23 24 25 26 27
28 }
29 printf ("%d %d
30 return 0;
31 }
• What do the programs do?
• In program 6, what is the variable state used for?
Explanation / Answer
If you post more than 1 question, as per chegg guidelines I have to answer only question.
1.
(a) Both the programs read user input and print the input enetered by the user. This goes on untill the end of file is reached.
(b) There is no difference in the terms of the output given by both the programs. The main difference is that in the first program, the input entered by the user is first read even before the while loop starts. Also in the while loop, at each iteration we scan another input entered by the user.
While in the second program, the input eneterd by the user is not saved in any variable, but the getchar() function is directly used in the while loop and compared with EOF there only. Also, unlike the first program, we don't read the input again in the body of the while loop, but rather inside the condition block only.
(c)
c = getchar() != EOF;
In the above statement, when the input is scanned by the user, the input entered by the user is saved in the variable c and then it is compared with EOF.
c = (getchar() != EOF);
In the above statement, when the input is scanned by the user, the input entered by the user is scompared with EOF and the boolean value we get after comparison is saved in c.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.