I have a homework assignment that requires user to input a set of real numbers. I must store these into an array of size 20, and must print the array in floats.
My problem here is that my array is printing more than the five numbers that are required. the five numbers are 10, 37, 15, 21, 18.
I need help printing only the five numbers, in float with one decimal place.
I'm Using Centos6.7 in Oracle VM VirtualBox, with gedit text editor. Any help is appreciated.
#include <stdio.h>
#define SIZE 20
int main(void)
{
int i, inputs[SIZE];
printf("Enter real numbers, up to %d, q to quit\n", SIZE);
for(i=0; i < SIZE; i++)
scanf("%d", &inputs[i]);
printf("You entered the following values:\n");
for(i=0; i < SIZE; i++)
printf("%4d", inputs[i]);
printf("\n");
return 0;
}
This is the output of the program:
[ee2372@localhost cprog]$ gcc jperez_aver.c
[ee2372@localhost cprog]$ ./a.out
Enter real numbers, up to 20, q to quit
10 37 15 21 18 q
You entered the following values:
10 37 15 21 18 04195443 0-503606696327674196037 0-891225184 494195968 0 0 04195552 0
gcc jperez_aver.c -Wall -Wextra -pedantic -std=c11.