Site hosted by Angelfire.com: Build your free website today!

Chapter 3 - Compiling and Running Your First Program

List of Questions


Back to Home Page

Question 1

Type in and run the six programs presented in this chapter. Compare the output presented after each program in the text.

Answer 1

Basic instruction...

Back to Top

Question 2

Write a program that prints the following text at the terminal:

  1. In C, lowercase letters are significant.
  2. main is where program execution begins.
  3. Opening and closing braces enclose program statements in a routine.
  4. All program statements must be terminated my a semicolon.

Answer 2


/* Chapter 3 Exercise 2 */

#include <stdio.h>

int main (void)
{
	printf ("1. In C, lowercase letters are significant.\n");
	printf ("2. 'main' is where the execution begins.\n");
	printf ("3. Opening and closing braces enclose program statements in a routine.\n");
	printf ("4. All program statements must be terminated by a semicolon.\n");
	
	return 0;
}	

Back to Top

Question 3

What output would you expect from the following program?


/* Chapter 3 Exercise 3 */

#include <stdio.h>

int main (void)
{
	printf ("Testing....");
	printf ("....1");
	printf ("...2");
	printf ("..1");
	printf ("\n");
	
	return 0;
}	

Answer 3

Testing.......1...2..3 (followed by a blank line)

Back to Top

Question 4

Write a program that subtracts the value of 15 from 87 and displays the result, together with an appropriate message, at the terminal.

Answer 4


/*Chapter 3 Exercise 4*/

#include <stdio.h>

int main (void)
{
	int value1, value2, sum;
	value1 = 87;
	value2 = 15;
	sum = value1 - value2;
	
	printf ("%i minus %i is %i\n", value1, value2, sum);
	printf ("A simple calculation using C.\n");
	
	return 0;
}

Back to Top

Question 5

Identify the syntactic errors in the following program. Then, type in and run the corrected program to ensure you have correctlty identified all the mistakes.


/*Chapter 3 Exercise 5*/

#include <stdio.h>

int main (Void)
(
	INT sum;
	/*COMPUTE RESULT
	sum = 25 + 37 - 19
	/*DISPLAY RESULTS //
	printf ("The answer is %i\n" sum);
	
	return 0;
}

Answer 5


/*Chapter 3 Exercise 5*/

#include <stdio.h>

int main (void)                             //Capitals matter
{                                           //Proper brackets
	int sum;                            //Capitals matter
	/*COMPUTE RESULT*/                  //Must close this type of comment
	sum = 25 + 37 - 19;                 //Must end with semicolon                  
	/*DISPLAY RESULTS*/                 //Must close with same comment
	printf ("The answer is %i\n", sum); //Must seperate with comma
	
	return 0;
}


Back to Top

Question 6

What output might you expect from the following program?


/*Chapter 3 Exercise 6*/

#include <stdio.h>

int main (void) 
{    
	int answer, result;
	
	answer = 100;
	result = answer - 10;
        printf ("The result is %i\n", result + 5);
	
	return 0;
}

Answer 6

The result is 95 (Followed by a blank line)

Back to Top

Back to Home Page