c - 10 element array -
my teacher gave assignment me. question below:=
write program prompts user enter 10 double numbers. program should accomplish follwing:
a. store information in 10-element array. b. display 10 numbers user.
i of above in main().
hint: should use loops, not hardcode values 0 through 9. should easy convert program accept 1000 numbers instead of 10.
for bonus mark, @ least 1 of tasks (a or b) in separate function. pass array function; not use global (extern) variables.
i confused above. wrote program in source code. doing wrong? below:=
#include<stdio.h> int main(void) { int number[10]; int i; (i = 0; <10; i++) printf("%d.\n", i, number[i]); printf("\n\npress [enter] exit program.\n"); fflush(stdin); getchar(); return 0; }
thanks.
not bad far, i'd make following comments:
- if need input double numbers, should use
double
ratherint
. - you need statement (maybe in current loop possibly in loop preceding current one) inputs numbers.
scanf
this. - using
%d
printf
integers, not doubles. have figured out format string used when lookedscanf
above. - bravo using correct
int main(void)
form , not includingconio.h
:-)
once you've figured bits out, can worry doing in separate function.
Comments
Post a Comment