Answers 843
F
scanf( “%d”, &x );
printf( “\nThe value entered is %d\n”, x );
return 0;
}
- It’s typical to edit a program to allow only specific values to be accepted. The fol-
lowing is one way to accomplish this exercise:
#include <stdio.h>
int x;
int main( void )
{
puts( “Enter an even integer value” );
scanf( “%d”, &x );
while( x % 2 != 0)
{
printf( “\n%d is not even, Please enter an even \
number: “, x );
scanf( “%d”, &x );
}
printf( “\nThe value entered is %d\n”, x );
return 0;
}
- The code is as follows:
#include <stdio.h>
int array[6], x, number;
int main( void )
{
/ loop 6 times or until the last entered element is 99 /
for( x = 0; x < 6 && number != 99; x++ )
{
puts( “Enter an even integer value, or 99 to quit” );
scanf( “%d”, &number );
while( number % 2 == 1 && number != 99)
{
printf( “\n%d is not even, Please enter an even \
number: “, number);
scanf( “%d”, &number );
}
array[x] = number;
}
/ now print them out... /
for( x = 0; x < 6 && array[x] != 99; x++ )
{
printf( “\nThe value entered is %d”, array[x] );
49 448201x-APP F 8/13/02 11:22 AM Page 843