注册 登录
编程论坛 C语言论坛

程序无法运行,求大神指点

靖琼 发布于 2019-09-24 23:25, 1958 次点击
void main()
{
    int a[8]={3,5,7,9,11,13,15,17};
    for(int i=0;i<8;i++)
    {
        printf("%5d",a[i]);
        if((i+1)%4==0)printf("\n");
    }
}
5 回复
#2
靖琼2019-09-24 23:34
运行结果应该是:3   5   7   9
               11  13  15  17

我用C/C++程序设计学习软件无法运行
#3
rjsp2019-09-25 08:30
什么叫“无法运行”,你要说出具体的错误。
比如用gcc编译时会报错
warning: return type of 'main' is not 'int'
         void main()
              ^~~~


warning: implicit declaration of function 'printf'
         printf("%5d",a[i]);
         ^~~~~~
note: include '<stdio.h>' or provide a declaration of 'printf'

正确的代码应当是
程序代码:
#include <stdio.h>

int main( void )
{
    int a[8] = { 3,5,7,9,11,13,15,17 };
    for( size_t i=0; i<sizeof(a)/sizeof(*a); ++i )
    {
        printf( "%5d", a[i] );
        if( (i+1)%4 == 0 )
            putchar( '\n' );
    }
}

#4
自学的数学2019-09-25 10:42
程序代码:
#include <stdio.h>
main()
{
    int a[8]={3,5,7,9,11,13,15,17};
    for(int i=0;i<8;i++)
    {
        printf("%5d",a[i]);
        if((i+1)%4==0)printf("\n");
    }
}
#5
黄巧健2019-09-25 17:00
int i先定义,再把i放入for里面
#6
wlcsss1232019-09-25 17:06
我可以运行啊  你不会没有加#include<stdio.h>把
1