
c语言输出1-10,用for循环
WriteaCprogramthatoutputstostandardoutthenumbersfrom1to10withcommaseparationusinga'fo...
Write a C program that outputs to standard out the numbers from 1 to
10 with comma separation using a 'for' loop. This list of numbers should be on a
single line (put a newline character at the end of the line). Place your answer in the
file called 'count.c' in the Q3 directory. When run from the command line you should
see:
$ ./count
1,2,3,4,5,6,7,8,9,10
$ 展开
10 with comma separation using a 'for' loop. This list of numbers should be on a
single line (put a newline character at the end of the line). Place your answer in the
file called 'count.c' in the Q3 directory. When run from the command line you should
see:
$ ./count
1,2,3,4,5,6,7,8,9,10
$ 展开
7个回答
展开全部
以下是题目的 C 语言程序代码:
#include <stdio.h>int main() { int i; for (i = 1; i <= 10; i++) { printf("%d", i); if (i < 10) { printf(",");
}
} printf("\n"); return 0;
}c
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
printf("%d", i);
if (i < 10) {
printf(",");
}
}
printf("\n");
return 0;
}
在这个程序中,我们使用了一个 for 循环来迭代从 1 到 10 的数字。我们使用了 printf 函数来输出每个数字,并在需要的时候添加逗号。最后,我们在输出末尾添加了一个换行符,以便所有的数字都可以在同一行上打印出来。
将以上代码保存到 count.c 文件中,使用 C 编译器编译并执行该程序,即可得到题目所要求的输出。
$ gcc count.c -o count
$ ./count
1,2,3,4,5,6,7,8,9,10
#include <stdio.h>int main() { int i; for (i = 1; i <= 10; i++) { printf("%d", i); if (i < 10) { printf(",");
}
} printf("\n"); return 0;
}c
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
printf("%d", i);
if (i < 10) {
printf(",");
}
}
printf("\n");
return 0;
}
在这个程序中,我们使用了一个 for 循环来迭代从 1 到 10 的数字。我们使用了 printf 函数来输出每个数字,并在需要的时候添加逗号。最后,我们在输出末尾添加了一个换行符,以便所有的数字都可以在同一行上打印出来。
将以上代码保存到 count.c 文件中,使用 C 编译器编译并执行该程序,即可得到题目所要求的输出。
$ gcc count.c -o count
$ ./count
1,2,3,4,5,6,7,8,9,10
展开全部
希望有帮助
#include<stdio.h>
int main(){
for(int i = 1; i <= 10; i++){
if(i != 10){
printf("%d," i);
}
else{
printf("%d" i);
}
}
printf("\n" );
return 0;
}
#include<stdio.h>
int main(){
for(int i = 1; i <= 10; i++){
if(i != 10){
printf("%d," i);
}
else{
printf("%d" i);
}
}
printf("\n" );
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-07-18
展开全部
#include<stdio.h>
int main()
{
printf("1");
for(int i = 2; i <= 10; i++)
{
printf(",%d", i);
}
printf("\n");
return 0;
}
int main()
{
printf("1");
for(int i = 2; i <= 10; i++)
{
printf(",%d", i);
}
printf("\n");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-07-18
展开全部
#include<stdio.h>
main()
{
int i;
for(i=1;i<=10;i++)
printf("%d,",i);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-07-18
展开全部
for(n=1;n<11;n++)
{
printf(%d,n);
}
大概就是这样,字符可能不很准确。望采纳。
{
printf(%d,n);
}
大概就是这样,字符可能不很准确。望采纳。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询