1. 程式人生 > >C語言代碼編程題匯總:顯示表達式1*2+3*4+...+99*100的表示形式(采取交互的形式)

C語言代碼編程題匯總:顯示表達式1*2+3*4+...+99*100的表示形式(采取交互的形式)

stdio.h tdi input 字符型 6.0 tro vc++6.0 text class

顯示表達式1*2+3*4+...+99*100的表示形式(采取交互的形式)

程序源代碼如下:

 1 /*
 2     2017年6月8日08:03:38
 3     功能:采取交互的形式輸出以下的表達式
 4 */
 5 #include "stdio.h"
 6 #include "string.h"
 7 
 8 int main()
 9 {
10     char seq[1000];
11     int i, j = 0, first, second, num;
12     printf("please input a odd number: ");
13     scanf("%d",&num);
14 if(num <= 10) 15 { 16 for (i = 1; i <= num; i++) 17 { 18 if (i % 2 != 0) 19 seq[j++] = 0 + i,seq[j++] = *; 20 else if(i % 2 == 0 && i != num) 21 seq[j++] = 0 + i,seq[j++] = +; 22 else if
(i == num) 23 seq[j++] = 0 + 1,seq[j++] = 0; 24 } 25 } 26 else if(num > 10 && num < 100) 27 { 28 for (i = 1; i <= num; i++) 29 { 30 if (i < 10) 31 if (i % 2 != 0) 32 seq[j++] =
0 + i,seq[j++] = *; 33 else 34 seq[j++] = 0 + i,seq[j++] = +; 35 else if (i >= 10 && i < num) 36 { 37 first = i % 10; 38 second = (i - first) / 10; 39 if (i % 2 != 0) 40 seq[j++] = 0 + second,seq[j++] = 0 + first,seq[j++] = *; 41 else if (i % 2 == 0 && i != num) 42 seq[j++] = 0 + second,seq[j++] = 0 + first,seq[j++] = +; 43 } 44 else if (i == num) 45 seq[j++] = 0 + second ,seq[j++] = 0 + (first + 1) ; 46 } 47 48 } 49 else if(num == 100) 50 { 51 for (i = 1; i <= 100; i++) 52 { 53 if (i < 10) 54 if (i % 2 != 0) 55 seq[j++] = 0 + i,seq[j++] = *; 56 else 57 seq[j++] = 0 + i,seq[j++] = +; 58 else if (i >= 10 && i < 100) 59 { 60 first = i % 10; 61 second = (i - first) / 10; 62 if (i % 2 != 0) 63 seq[j++] = 0 + second,seq[j++] = 0 + first,seq[j++] = *; 64 else 65 seq[j++] = 0 + second,seq[j++] = 0 + first,seq[j++] = +; 66 } 67 else if (i == 100) 68 seq[j++] = 0 + 1,seq[j++] = 0,seq[j++] = 0; 69 } 70 } 71 seq[j] = \0; 72 puts(seq); 73 } 74 /* 75 總結: 76 在VC++6.0中顯示的結果: 77 ----------------------------------------------------------------- 78 please input a odd number: 98 79 1*2+3*4+5*6+7*8+9*10+11*12+13*14+15*16+17*18+19*20+21*22+23*24+25*26+27*28+29*30 80 +31*32+33*34+35*36+37*38+39*40+41*42+43*44+45*46+47*48+49*50+51*52+53*54+55*56+5 81 7*58+59*60+61*62+63*64+65*66+67*68+69*70+71*72+73*74+75*76+77*78+79*80+81*82+83* 82 84+85*86+87*88+89*90+91*92+93*94+95*96+97*98 83 84 please input a odd number: 100 85 1*2+3*4+5*6+7*8+9*10+11*12+13*14+15*16+17*18+19*20+21*22+23*24+25*26+27*28+29*30 86 +31*32+33*34+35*36+37*38+39*40+41*42+43*44+45*46+47*48+49*50+51*52+53*54+55*56+5 87 7*58+59*60+61*62+63*64+65*66+67*68+69*70+71*72+73*74+75*76+77*78+79*80+81*82+83* 88 84+85*86+87*88+89*90+91*92+93*94+95*96+97*98+99*100 89 ----------------------------------------------------------------- 90 註意:將整數型數據轉化成字符型數據的格式 91 char m; 92 int n; 93 m = n + ‘0‘;(像10、100之類的數據除外) 94 */

C語言代碼編程題匯總:顯示表達式1*2+3*4+...+99*100的表示形式(采取交互的形式)