如果有人可以提高效率,我真的很高兴.... THX MUahhh 解决方案 9月20日下午2:39,aslamhe ... @ yahoo.com写道: 请输入任意5位数字编号:56789 和输出是 5678 9 567 89 56 789 5 6789 如何编写这些程序...... 我的想法是这样的。 .. #include< stdio.h> void main() { int num; float num1,num2,n um3,num4; 浮动r1,r2,r3,r4; printf(请输入任意5位数字:); scanf("%d",& num); num1 = num / 10; num2 = num / 100; num3 = num / 1000; num4 = num / 10000; r1 = num%10; r2 = num%100; r3 = num%1000; r4 = num%10000; printf(" \ n%.0f%。0f",num1,r1); printf(" \ n%.0f%.0f",num2,r2); printf(" \ n%。0f%。0f",num3,r3); printf(" \ n%.0f%。0f",num4,r4);} __________________________________________________ _________________________ * ___ 当我输入数字56789时出现问题。当我输入56789时,输出变为 垃圾... 但是如果我输入12345该程序很好地执行... .. 任何人都可以告诉我编码有什么问题... 如果有人能让它变得更有效,我真的很高兴.. .. THX MUahhh 更正 9月20日,2 :下午39点,aslamhe ... @ yahoo.com写道: 请输入任意5位数字:56789 和输出是 5678 9 567 89 56 789 5 6789 如何编写那些程序...... 我的想法是这样的... #include< stdio.h> void main() { int num; float num1,num2,num3,num4; float r1,r2,r3,r4; printf(请输入任意5位数字:); scanf("%d",& num); num1 = num / 10; num2 = num / 100; num3 = num / 1000; num4 = num / 10000; r1 = num%10; r2 = num%100; r3 = num% 1000; r4 = num%10000; printf(" \ n%.0f%.0f",num1,r1); printf(" \ n%.0f%.0f",num2,r2); printf(" \ n%。0f%。0f",num3,r3); printf(" \ n%.0f%。0f",num4,r4);} __________________________________________________ _________________________ * ___ 当我输入数字56789时出现问题。当我输入56789时,输出变为 垃圾... 但是如果我输入12345该程序很好地执行... .. 任何人都可以告诉我编码有什么问题...... 如果有人能让它更有效,我真的很感激.. .. THX MUahhh 2007年9月19日星期三23:39:27 -0700,aslamhenry写道: 请输入任意5位数字:56789 且输出为 5678 9 567 89 56 789 5 6789 怎么样写那些节目...... 我的想法是这样的... #include< stdio.h> void main() main返回一个int。请参阅 www.c-faq.com ,问题1.25b。 { int num; float num1,num2,num3,num4; float r1 ,r2,r3,r4; printf(请输入任意5位数字:); scanf("%d" ,试验#); [snip] 当我输入数字56789时出现问题。输出变为 垃圾当我把56789 ...... 但是如果我输入12345程序就会很好地执行..... 任何人都可以告诉我编码有什么问题...... 保证适合int的最大值是32767.声明 num作为一个长的(你需要使用%ld而不是%d)。 顺便说一下,绝对不需要使用浮点 $ b $在这里,整数会这样做,或者更好的仍然认为输入为 a字符串,就像你在另一个帖子中被告知的那样。 这样做: 从stdin读取6个字符; 如果前5个字符是数字,第6个字符是空格, 输入正常;正如你在另一个线程中被告知的那样处理它; 别做一些明智的事情。请注意,如果 失败,则scanf不会触及num(例如,没有数字数据,但字母或 标点符号或其他),在这种情况下,num保持未初始化状态。不要 使用scanf(),除非没有更好的选择。提示:总有 是更好的选择。 - Army1987(将NOSPAM替换为电子邮件 ;) 如果你是从Windows机器发送电子邮件,请关闭微软的 愚蠢的??智能行情?特征。这样你就可以避免通过你的邮件洒垃圾字符了。 - Eric S. Raymond和Rick Moen 9月20日晚上7点10分,Army1987< army1 ... @ NOSPAM.itwrote: 2007年9月19日星期三23:39:27 -0700,aslamhenry写道: please key在任何5位数字:56789 和输出是 5678 9 567 89 56 789 5 6789 如何编写这些程序.... .. 我的想法是这样的... #include< stdio.h> void main() main返回一个int。见www.c-faq.com,问题1.25b。 { int num; float num1 ,num2,num3,num4; float r1,r2,r3,r4; printf("请输入任意5位数字:"); scanf("%d" ;,试验#); [snip] 当我输入数字56789时出现问题。输出变为 垃圾,当我把56789 ...... 但是如果我输入12345程序执行得很好..... 任何人都可以告诉我编码有什么问题... 保证适合int的最大值是32767.声明 num为long(你需要使用%ld而不是%d)。 顺便说一下,绝对不需要使用浮动点 这里,整数会这样做,或者更好的仍然认为输入为 a字符串,就像你在另一个帖子中被告知的那样。 Do像这样: 从stdin读取6个字符; 如果前5个字符是数字而第6个字符是空格, 输入正常;正如你在另一个线程中被告知的那样处理它; 别做一些明智的事情。请注意,如果 失败,则scanf不会触及num(例如,没有数字数据,但字母或 标点符号或其他),在这种情况下,num保持未初始化状态。不要 使用scanf(),除非没有更好的选择。提示:总有 是更好的选择。 - Army1987(将NOSPAM替换为电子邮件 ;) 如果您要从Windows机器发送电子邮件,请关闭Microsoft的 愚蠢的智能行情特征。这样你就可以避免通过你的邮件洒垃圾字符了。 - Eric S. Raymond和Rick Moen-隐藏引用文字 - - 显示引用文字 - 如何使用%ld ??因为我是一个新手....还有很多编码, 我以前从未见过 please key in any 5 digits number : 56789and the ouput is5678 9567 8956 7895 6789how to write those program...... my idea is like this...#include <stdio.h> void main(){int num;float num1,num2,num3,num4;float r1,r2,r3,r4; printf("please key in any 5 digit number:");scanf("%d",&num); num1=num/10;num2=num/100;num3=num/1000;num4=num/10000 ; r1=num%10;r2=num%100 ;r3=num%1000 ;r4=num%10000 ; printf("\n %.0f %.0f",num1,r1);printf(" \n %.0f %.0f",num2,r2);printf(" \n %.0f %.0f",num3,r3);printf(" \n %.0f %.0f",num4,r4);}__________________________________________________ ____________________________ the problem occur when i entered nnumber 56789.It output becomerubbish when i put 56789...but if i key in 12345 the program excute nicely..... anyone can tell what wrong with my coding... and i really appriciate if someone can make it more efficient.... THX MUahhh 解决方案 On Sep 20, 2:39 pm, [email protected] wrote:please key in any 5 digits number : 56789and the ouput is5678 9 567 89 56 789 5 6789how to write those program......my idea is like this...#include <stdio.h>void main(){ int num; float num1,num2,num3,num4; float r1,r2,r3,r4;printf("please key in any 5 digit number:");scanf("%d",&num);num1=num/10;num2=num/100;num3=num/1000;num4=num/10000 ;r1=num%10;r2=num%100 ;r3=num%1000 ;r4=num%10000 ;printf("\n %.0f %.0f",num1,r1);printf(" \n %.0f %.0f",num2,r2);printf(" \n %.0f %.0f",num3,r3);printf(" \n %.0f %.0f",num4,r4);}__________________________________________________ _________________________*___the problem occur when i entered nnumber 56789.It output becomerubbish when i put 56789...but if i key in 12345 the program excute nicely.....anyone can tell what wrong with my coding...and i really appriciate if someone can make it more efficient....THX MUahhhCORRECTION On Sep 20, 2:39 pm, [email protected] wrote:please key in any 5 digits number : 56789and the ouput is5678 9 567 89 56 789 5 6789how to write those program......my idea is like this...#include <stdio.h>void main(){ int num; float num1,num2,num3,num4; float r1,r2,r3,r4;printf("please key in any 5 digit number:");scanf("%d",&num);num1=num/10;num2=num/100;num3=num/1000;num4=num/10000 ;r1=num%10;r2=num%100 ;r3=num%1000 ;r4=num%10000 ;printf("\n %.0f %.0f",num1,r1);printf(" \n %.0f %.0f",num2,r2);printf(" \n %.0f %.0f",num3,r3);printf(" \n %.0f %.0f",num4,r4);}__________________________________________________ _________________________*___the problem occur when i entered nnumber 56789.It output becomerubbish when i put 56789...but if i key in 12345 the program excute nicely.....anyone can tell what wrong with my coding...and i really appreciate if someone can make it more efficient....THX MUahhh On Wed, 19 Sep 2007 23:39:27 -0700, aslamhenry wrote: please key in any 5 digits number : 56789and the ouput is5678 9 567 89 56 789 5 6789how to write those program......my idea is like this...#include <stdio.h>void main()main returns an int. See www.c-faq.com, question 1.25b. {int num; float num1,num2,num3,num4; float r1,r2,r3,r4;printf("please key in any 5 digit number:");scanf("%d",&num);[snip]the problem occur when i entered nnumber 56789.It output becomerubbish when i put 56789...but if i key in 12345 the program excute nicely.....anyone can tell what wrong with my coding...The maximum value guaranteed to fit in an int is 32767. Declarenum as a long (you''ll need to use "%ld" instead of "%d").By the way, there is absolutely no need to use floating pointhere, integers would do it, or better still consider the input asa string as you were told in the other thread.Do like this:read 6 characters from stdin;if the first 5 characters are digits and the sixth is whitespace,the input is ok; process it as you were told in the other thread;else do something sensible. Note that scanf doesn''t touch num ifit fails (e.g. there are no numeric data but letters orpunctuation or else), in which case num stays uninitialized. Don''tuse scanf() unless there is no better choice. Hint: there alwaysis a better choice. --Army1987 (Replace "NOSPAM" with "email")If you''re sending e-mail from a Windows machine, turn off Microsoft''sstupid a??Smart Quotesa?? feature. This is so you''ll avoid sprinkling garbagecharacters through your mail. -- Eric S. Raymond and Rick Moen On Sep 20, 7:10 pm, Army1987 <[email protected]:On Wed, 19 Sep 2007 23:39:27 -0700, aslamhenry wrote: please key in any 5 digits number : 56789 and the ouput is 5678 9 567 89 56 789 5 6789 how to write those program...... my idea is like this... #include <stdio.h> void main() main returns an int. Seewww.c-faq.com, question 1.25b. { int num; float num1,num2,num3,num4; float r1,r2,r3,r4; printf("please key in any 5 digit number:"); scanf("%d",&num);[snip] the problem occur when i entered nnumber 56789.It output become rubbish when i put 56789... but if i key in 12345 the program excute nicely..... anyone can tell what wrong with my coding... The maximum value guaranteed to fit in an int is 32767. Declarenum as a long (you''ll need to use "%ld" instead of "%d").By the way, there is absolutely no need to use floating pointhere, integers would do it, or better still consider the input asa string as you were told in the other thread.Do like this:read 6 characters from stdin;if the first 5 characters are digits and the sixth is whitespace,the input is ok; process it as you were told in the other thread;else do something sensible. Note that scanf doesn''t touch num ifit fails (e.g. there are no numeric data but letters orpunctuation or else), in which case num stays uninitialized. Don''tuse scanf() unless there is no better choice. Hint: there alwaysis a better choice.--Army1987 (Replace "NOSPAM" with "email")If you''re sending e-mail from a Windows machine, turn off Microsoft''sstupid "Smart Quotes" feature. This is so you''ll avoid sprinkling garbagecharacters through your mail. -- Eric S. Raymond and Rick Moen- Hide quoted text -- Show quoted text -how to use %ld??since im a newbie....there still a lot of coding thative never seen before 这篇关于呜咽。有人可以帮我???? plsss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 00:31