使用函数和数组

Ord*_*rdo 2 c

我的下面的小程序将从用户获取5个数字,将它们存储到整数数组中并使用函数将它们打印出来.真诚地它不起作用,我的输出总是"00000".我找不到错误,所以我很乐意提出任何建议.谢谢.

#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;
}
Run Code Online (Sandbox Code Playgroud)

Car*_*rum 5

你想要的%d不是&d你的scanf()格式字符串.这个错误是通过使用调试器很容易识别的- 我建议学习如何使用最适合您的开发系统的其他任何一个.

打开更多警告进行编译也可能已经检测到这一点.像"太多的格式参数"之类的东西.