简单的程序在c中不执行
#include<stdio.h>
main()
{
int i, int a[5]={1,2,48,3,88};
for(i=0;i<4;i++)
{
if (a[i]<a[i+1])
{
printf("%d",a[i]);
}
else
{
printf("can't print");
}
}
}
该程序根本没有执行。我的目标是如果当前数字小于下一个数字则打印该数字。它应该打印,否则将打印无法打印。
#include<stdio.h>
main()
{
int i, int a[5]={1,2,48,3,88};
for(i=0;i<4;i++)
{
if (a[i]<a[i+1])
{
printf("%d",a[i]);
}
else
{
printf("can't print");
}
}
}
The program is not executing at all. My aim was to print the number if the current number is less than the next number. It should print or else it will print can't print.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在当前版本的 C 中,您应该为
main
指定返回类型,并且返回类型必须为int
。我还建议指定参数列表。如果您想要单独声明
i
和a
(我推荐),那么您需要使用分号来分隔它们,如果您想要一个声明(我不会这样做)不推荐)您需要省略第二个int
。或者
您的
printf
字符串应以\n
结尾,以确保它们按预期输出:In current versions of C you should specify a return type for
main
and the return type must beint
. I also recommend specifying the parameter list.If you want separate declarations for
i
anda
(which I recommend) then you need to use a semi-colon to separate them, if you want one declaration (which I wouldn't recommend) you need to omit the secondint
.or
Your
printf
strings should end with a\n
to ensure they are output where expected:在每个 printf 中放置一个终止换行符
\n
,例如printf("can't print\n");
或调用fflush(NULL)
。您的声明应分隔为
“请适当缩进您的 C 代码”(在 Linux 上,
indent
实用程序可以提供帮助)。不要忘记编译带有警告和调试信息的程序(例如 Linux 上的
gcc -Wall -g myprog.c -o myprog
)Put a terminating newline
\n
in every printf, e.g.printf("can't print\n");
or callfflush(NULL)
.Your declarations should be separated as
Please indent your C code appropriately (on Linux, the
indent
utility can help).Don't forget to compile your program with warnings and debugging information (e.g.
gcc -Wall -g myprog.c -o myprog
on Linux)