Re: [問題] C語言運算式的問題~

看板TransCSI作者 (小葉子)時間18年前 (2007/08/13 20:19), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
Problem-2: Write a program that prompts a user for an integer value in the range 0 to 32767, and then prints the individual digits of the number on a line with three spaces between the digits. The first line is to start with the leftmost digit and print all five digits; the second line is to start with the second digit from the left and print four digits, and so on. For example. If the user enters 1234, your program should print: 0 1 2 3 4 1 2 3 4 2 3 4 3 4 4 #include<stdio.h> main(){ int digit[5],n,i,j; printf("Please input an integer number: "); scanf("%d",&n); for(i=4;i>=0;i--){ digit[i] = n % 10; n = n / 10; } for(i=0;i<5;i++){ for(j=i;j<5;j++){ printf("%d ",digit[j]); } printf("\n"); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.164.74.16

08/13 20:34, , 1F
謝謝你喔~
08/13 20:34, 1F
文章代碼(AID): #16m4nbGO (TransCSI)
文章代碼(AID): #16m4nbGO (TransCSI)