Using functions and arrays
Posted
by
Ordo
on Stack Overflow
See other posts from Stack Overflow
or by Ordo
Published on 2011-01-15T05:29:58Z
Indexed on
2011/01/15
5:53 UTC
Read the original article
Hit count: 170
c
Hello! My little program below shall take 5 numbers from the user, store them into an array of integers and use a function to print them out. Sincerly it doesn't work and my output is always "00000". I can't find a mistake, so i would be glad about any advice. Thanks.
#include <stdio.h>
void printarray(int intarray[], int n)
{
int i;
for(i = 0; i < n; i ++)
{
printf("%d", intarray[i]);
}
}
int main ()
{
const int n = 5;
int temp = 0;
int i;
int intarray [n];
char check;
printf("Please type in your numbers!\n");
for(i = 0; i < n; i ++)
{
printf("");
scanf("&d", &temp);
intarray[i] = temp;
getchar();
getchar();
}
printf("Do you want to print them out? (yes/no): ");
scanf("%c", &check);
if (check == 'y')
printarray(intarray, n);
getchar();
getchar();
return 0;
}
© Stack Overflow or respective owner