看板 TransCSI 關於我們 聯絡資訊
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
ssnn:謝謝你喔~ 08/13 20:34