本文介绍了一个简单的程序,需要看看哪里有错误:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 问候,这是我编程的第一年和第3周的这个 所以算我是一个纯粹的新手。 我正在尝试制作一个程序一个数字和打印开始 如下: 输入3: * ** *** 输入6: * ** *** **** ***** ****** 正如您所看到的那样,我尝试制作的程序会产生与输入数字相同的行数 ,每行增加一颗星。 这个是我写的程序: #include< stdio.h> star(int x) { int i = 1; while(i< = x) { printf(" ; *"); i ++; } } print(int x ){ int start = 1; int end = x; while(start< = end) { printf("%d \ n",sta r(开始)); 开始++; } } main() { printf(输入值\ n); int veri; scanf("%d" ,& veri); print(veri); } 似乎有效,但有一个错误: 我总是在这样的星星后得到一个数字: Ex: 输入值 8 * 2 ** 3 *** 4 **** 5 ***** 6 ****** 7 ******* 8 ** ****** 9 提前致谢:)Greetings , This is my first year at programming and 3rd week at thisso count me as a pure newbie.I am trying to make a program that gets a number and prints out startsas this:For input 3 :******For input 6:*********************As you see the program I am trying to make generates as much as linesas the input number , one star increasement at each line.This is the program I wrote:#include <stdio.h>star(int x){int i=1;while(i<=x){printf("*");i++;}}print(int x){int start = 1;int end = x;while (start <= end){printf("%d \n", star(start) );start++;}}main(){printf("Enter value \n");int veri;scanf("%d", &veri);print(veri);}Seems works but with a bug:I always get a number after stars such as this:Ex:Enter value8*2**3***4****5*****6******7*******8********9Thanks in advance :)推荐答案 不确定你想要完成什么通过在printf中调用star 函数。也许我错过了什么。如果你只需要把它拿出去并在你的明星 函数中添加新行的打印,它似乎输出你所描述的想要的东西: #include< stdio.h> star(int x) { int i = 1; while(i< = x) { printf(" *"); i ++; } printf(" \ n"); } printstar(int x){ int start = 1; int end = x; while(start< = end) { star(start); start ++; } } main() { printf("输入值\ n"); int veri; scanf("%d",& veri); printstar(veri); }Not sure what you were trying to accomplish by calling the starfunction from within the printf. Maybe I am missing something. If youjust take that out and add the printing of the new line in your starfunction it seems to output what you described as wanting:#include <stdio.h>star(int x){int i=1;while(i<=x){printf("*");i++;}printf("\n");}printstar(int x){int start = 1;int end = x;while (start <= end){star(start) ;start++;}}main(){printf("Enter value \n");int veri;scanf("%d", &veri);printstar(veri);} 嗯,你至少尝试过,这是一个很好的开始。还不错 所有,但有一些事情需要注意:Well, you''ve tried at least, and that''s a great start. Not bad atall, but there are some things to note: 这是有效的 - 返回类型默认为" INT"如果你没有明确地提供 - 但这不是一个好主意,它也不是最新的C语言标准所支持的。鉴于你没有给b $ b返回任何东西,也许是无效。在这里是合适的。This is valid - the return type defaults to "int" if you don''t supplyone explicitly - but it isn''t a great idea, and it also isn''tsupported by the latest C language standard. Given that you don''treturn anything, perhaps "void" would be appropriate here. 这里是你看到的那些数字进来的地方。在printf中的%d() 告诉它看起来对于一个数字,这是星(开始)返回的。 因为你实际上没有返回任何东西,所以 被打印的数字不能被预测。请注意这一点。 star(start); printf(" \ n"); $ b如果没有打印那个数字,$ b就可以很好地工作。Here''s where those numbers you''re seeing come in. That %d in printf()tells it to look for a number, which is what star(start) returns.Since you didn''t actually return anything, though, the number thatgets printed can''t be predicted. Watch out for that.star(start);printf( "\n" );will work quite nicely without printing that number. 这样会更好 int main(无效) ....This would be better asint main(void).... ....这意味着你会想要在这里返回一些东西。 0表示成功, 所以 返回0;....which means you''ll want to return something here. 0 means success,soreturn 0; 可能比我的第一个C程序好... - C. Benson Manica |我*应该*知道我在说什么 - 如果我 cbmanica(at)gmail.com |不,我需要知道。火焰欢迎。Probably better than my first C program...--C. Benson Manica | I *should* know what I''m talking about - if Icbmanica(at)gmail.com | don''t, I need to know. Flames welcome. 嗯,你至少尝试过,这是一个很好的开始。还不错 所有,但有一些事情需要注意:Well, you''ve tried at least, and that''s a great start. Not bad atall, but there are some things to note: 这是有效的 - 返回类型默认为" INT"如果你没有明确地提供 - 但这不是一个好主意,它也不是最新的C语言标准所支持的。鉴于你没有给b $ b返回任何东西,也许是无效。在这里是合适的。This is valid - the return type defaults to "int" if you don''t supplyone explicitly - but it isn''t a great idea, and it also isn''tsupported by the latest C language standard. Given that you don''treturn anything, perhaps "void" would be appropriate here. 这里是你看到的那些数字进来的地方。在printf中的%d() 告诉它看起来对于一个数字,这是星(开始)返回的。 因为你实际上没有返回任何东西,所以 被打印的数字不能被预测。请注意这一点。 star(start); printf(" \ n"); $ b如果没有打印那个数字,$ b就可以很好地工作。Here''s where those numbers you''re seeing come in. That %d in printf()tells it to look for a number, which is what star(start) returns.Since you didn''t actually return anything, though, the number thatgets printed can''t be predicted. Watch out for that. star(start); printf( "\n" );will work quite nicely without printing that number. 这样会更好 int main(无效) ...This would be better asint main(void)... ...这意味着你会想要在这里归还一些东西。 0表示成功, 所以 返回0;...which means you''ll want to return something here. 0 means success,soreturn 0; 可能比我的第一个C程序好... - C. Benson Manica |我*应该*知道我在说什么 - 如果我 cbmanica(at)gmail.com |不,我需要知道。火焰欢迎。Probably better than my first C program...--C. Benson Manica | I *should* know what I''m talking about - if Icbmanica(at)gmail.com | don''t, I need to know. Flames welcome. 这篇关于一个简单的程序,需要看看哪里有错误:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 10:59