Code:
/*
This program is for practicing "array".
4/ 10/ 07
*/
#include <stdio.h>
#include <conio.h>
#define SIZE 11
void askContinue (void);
void askForNumber (void);
void sCalc (void);
float num;
int a [SIZE] = {2, 8, -7, 9, 0, 11, 14, 7, 12, 3, 5};
int main ()
{
printf ("This program has an array of size 11 which is initialized.\nYou may enter a number which\n");
printf ("will be multiplied to every value in the array.\n\n");
printf ("Initialized to: 2, 8, -7, 9, 0, 11, 14, 7, 12,3, 5");
askContinue ();
}//main
void askContinue ()
{
char answer;
printf ("\nIf you want to continue press y");
printf ("\nOtherwise hit anyother key to exit\n\n");
scanf ("%c\n", &answer);
switch (answer) {
case 'y' :
askForNumber ();
break;
default :
printf ("Goodbye!");
getch ();
printf (&answer);
return 0;
}//switch
} //askContinue
void askForNumber ()
{
printf ("\n Enter a number to be multiplied\n");
scanf ("\n%f\n", &num);
printf ("\n\nYou entered the number: %f\n\n", num );
sCalc ();
}//askForNumber
void sCalc ()
{
printf ("The original values of the array were:\n\n");
printf ("%s%9s\n", "Index", "value");
for (int i = 0; i <SIZE;i++)
{
printf ("%3d%9d", i, a[i]);
printf ("\n");
}
printf (" \nThe new values of the array are:\n\n");
for (int i = 0; i <= SIZE-1; i++)
{
a [i] = a[i] * num;
printf ("%3d%9d", i, a[i]);
printf ("\n");
}
askContinue ();
}//sCalc
