Self-Test Program 4
Demonstration Self-Test Program 4 written in ANSI Standard C++
/****************************************************/
/* Source: prereq04.cpp */
/* */
/* Purpose: Demonstration self-test program #4. */
/* Written in ANSI Standard C++ */
/****************************************************/
#include <iostream>
using namespace std;
int main(void)
{
int theArray[10];
int x;
int i, counter;
/* Input an integer from the user between 1 and 25 */
x = 0; /* Initialize the variable */
while((x < 1) || (x > 25)) /* Make the user input a number in the correct range */
{
cout << "Please input a number from 1 to 25: ";
cin >> x;
if((x < 1) || (x > 25))
cout << "\nNumber must be from 1 to 25. Try again\n";
}
cout << "\n\n"; /* Print a couple of blank spaces */
// Store values in the array
for(i=0; i<10; i++)
{
theArray[i] = i * x;
}
/* Print all values in the array */
counter = 0;
while(counter < 10)
{
cout << "Value in array[" << counter << "] = " << theArray[counter] << "\n";
counter++;
}
return 0;
}
Demonstration Self-Test Program 1 written in ANSI Standard C
/****************************************************/
/* Source: prereq04.c */
/* */
/* Purpose: Demonstration self-test program #4. */
/* Written in ANSI Standard C */
/****************************************************/
#include <stdio.h>
int main(void)
{
int theArray[10];
int x;
int i, counter;
/* Input an integer from the user between 1 and 25 */
x = 0; /* Initialize the variable */
while((x < 1) || (x > 25)) /* Make the user input a number in the correct range */
{
printf("Please input a number from 1 to 25: ");
scanf("%d", &x);
if((x < 1) || (x > 25))
printf("\nNumber must be from 1 to 25. Try again\n");
}
printf("\n\n"); /* Print a couple of blank spaces */
// Store values in the array
for(i=0; i<10; i++)
{
theArray[i] = i * x;
}
/* Print all values in the array */
counter = 0;
while(counter < 10)
{
printf("Value in array[%d] = %d\n", counter, theArray[counter]);
counter++;
}
return 0;
}