Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Loops (c)

Instructions: Think about each question and write the answer in your notebook.


White Box Testing

1. Fix the errors in this C source code. There are 2 errors.

#include <stdio.h>
void main( )
{
int loop;
int stop;
printf("\nThis program displays ASCII characters.");
printf("\nIt begins at 1 and ends before the number you type here: ");
scanf("%d", &stop);
for(loop = 1; loop < loop; ++loop)

printf("\n%d\t%c", loop, loop)

}

2. Fix the errors in this C source code. There are 2 errors.

#include <stdio.h>
void main( )
{
int count;
int num;
printf("\nThis program makes a rectangle of ASCII characters.");
printf("\nType a number from 11-20: ");
scanf("%d", &num);
printf("\n%c%c%c", num, num, num);
for(count = 31; count < num; ++count)

printf("\n%c %c", num, num);

printf("\n%c%c%c", num, num);
}

3. Fix the errors in this C source code. There are 2 errors.

#include <stdio.h>
void main( )
{
int temp = 32;
int answer;
int tries = 3;
printf("\nYou have three tries to answer this question:");
for( ; tries > 0; -tries)
{

printf("\nAt what temperature Fahrenheit does water freeze? ");
scanf("%d", answer);
if(answer == temp) {
printf("\nYes, water freezes at 32 degrees Fahrenheit.");
return;
}
else
printf("\nWrong.");
}
printf("\nYour country probably uses Celsius.");
}

Copyright
© 2001
Kristin Switala
Hosted by www.Geocities.ws

1