原帖由 小蠢 于 2009-10-27 08:17 PM 发表
我的题目是华语的~所以其实我也看不是很明白~(虽然他们说很简单)
所以写不出~
请问有谁可以帮帮我啊~
写一个程式印出100个星号(一次印一个)。每印10型号必须印一个newline字元(换行)。
答案要是这样的 ...
#include <IOSTREAM>
using namespace std;
int total = 10;
int star = 0;
int main() {
if(star++ < 10){
cout << "*";
}else{
star = 0;
if(--total == 0){system("PAUSE");return 0;}
cout << endl;
};
main();
}
复制代码
- #include <stdio.h>
- int main()
- {
- for (int i = 1; i <= 100; i++)
- i % 10 == 0 ? printf("\n") : printf("*");
- return 0;
- }
复制代码
- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(7) : error C2065: 'i' : undeclared identifier
- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(7) : error C2065: 'i' : undeclared identifier
复制代码
- #include <stdio.h>
- int main()
- {
- int i;
- for (i = 1; i <= 100; i++)
- i % 10 == 0 ? printf("\n") : printf("*");
- return 0;
- }
复制代码
- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- Microsoft (R) Incremental Linker Version 9.00.30729.01
- Copyright (C) Microsoft Corporation. All rights reserved.
- /out:star.exe
- star.obj
- C:\Users\Dhilip89\Desktop>star
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) | Powered by Discuz! X2.5 |