Question: 1. Study (write, compile, and run/test) the following two programs. ++++++++++++++++++++++++++++++++++++++++++++++++++ // Here goes brief description of the program - program 1 // Author: //

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

int main() {

int c;

 c = getchar(); while (c != EOF) { 
 putchar(c); c = getchar(); 

}

return 0; }

//++++++++++++++++++++++++++++++++++++++++++++++++++ // Here goes brief description of the program - program 2 // Author: // Date: // CSCI3100A-Spring2018-LA1

//++++++++++++++++++++++++++++++++++++++++++++++++++

#include

int main() {

int c;

 while ((c = getchar()) != EOF){ putchar(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

int main() {

long nc;

 nc = 0; while (getchar() != EOF) 
 ++nc; printf ("%ld ", nc); 

return 0; }

//++++++++++++++++++++++++++++++++++++++++++++++++++ // Here goes brief description of the program - program 4

// Author: // Date: // CSCI3100A-Spring2018-LA1

//++++++++++++++++++++++++++++++++++++++++++++++++++

#include

int main() {

double nc;

 for (nc = 0; getchar() != EOF; ++nc) ; 
 printf ("%.0f ", 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

int main() {

int c, nl;

 nl = 0; while ((c = getchar()) != EOF) 
 if (c ==  ) ++nl; 
 printf ("%d ", nl); 

return 0; }

1 //++++++++++++++++++++++++++++++++++++++++++++++++++

2 //

3 //

4 //

5 //

6 //++++++++++++++++++++++++++++++++++++++++++++++++++

7 #include

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?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!