1、
#include <stdio.h> #include <string> int main() { char ch[26]; ch[0] = 'a'; for (int i = 1; i < 26; i++) { ch[i] = 'a' + i; } for (int i = 0; i < 26; i++) { printf("%c", ch[i]); } getchar(); return 0; }
2、
#include <stdio.h> #include <string> int main() { int i, j; for (i = 1; i < 6; i++) { for (j = 0; j <i; j++) printf("$"); printf(" "); } getchar(); return 0; }
3、
#include <stdio.h> #include <string> int main() { int i, j; char ch[6]; ch[0] = 'F'; for (i = 1; i < 7; i++) { for (j = 0; j < i; j++) { ch[j] = 'F' - j; printf("%c", ch[j]); } printf(" "); } getchar(); return 0; }
4、
#include <stdio.h> #include <string> int main() { int i, j,k; k = 0; char ch[6]; ch[0] = 'A'; for (i = 1; i < 7; i++) { for (j = 0; j < i; j++) { ch[j] = 'A' + k; k++; printf("%c", ch[j]); } printf(" "); } getchar(); return 0; }
5、
#include <stdio.h> #include <string> int main() { int i; char c; printf("请输入大写字母:"); scanf("%c", &c); getchar(); i = c - 'A' + 1; for (int a = 0; a < i; a++) { //每一行采用三个for循环链接 char ch = 'A'- 1; for (int j = 0; j < (i - a - 1); j++) { //处理空格 printf(" "); } for (int j = 0; j <= a; j++) { //升序打印字母 printf("%c", ++ch); } for (int j = 0; j < a; j++) { //降序打印字母 printf("%c", --ch); } printf(" "); } getchar(); return 0; }
6、
#include <stdio.h> #include <string> int main() { int start, end, i,data,data_2,data_3; printf("请输入上限及下限:"); scanf("%d,%d", &start, &end); getchar(); i = end - start + 1; for (int a = 0; a < i; a++) { data = start + a; data_2 = data*data; data_3 = data_2*data; printf("%d %d %d ", data, data_2, data_3); } getchar(); return 0; }
7、
#include <stdio.h> #include <string> int main() { int a; char ch[20] = { 0 }; printf("请输入单词:"); scanf("%s", ch); getchar(); for (a = strlen(ch)-1; a >= 0; a--) { //下标比字符总是小一位,所以要减去1 printf("%c", ch[a]); } getchar(); return 0; }
8、
#include <stdio.h> #include <string> int main() { double a,b,c; printf("请输入两个浮点数:"); while (scanf("%lf,%lf", &a, &b)) { getchar(); c = (a - b) / (a*b); printf("两点之差除以两点之乘等于%lf ", c); printf("请输入两个浮点数:"); } getchar(); return 0; }
9、
#include <stdio.h> #include <string> void haha(double a, double b); double a, b, c; int main() { printf("请输入两个浮点数:"); while (scanf("%lf,%lf", &a, &b)) { getchar(); haha(a, b); } getchar(); return 0; } void haha(double a, double b) { c = (a - b) / (a*b); printf("两点之差除以两点之乘等于%lf ", c); printf("请输入两个浮点数:"); }
10、
#include <stdio.h> #include <string> void haha(double a, double b); int a, b, c, d, n; int sum = 0; int main() { printf("Enter lower and upper integer limits:"); scanf("%d,%d", &a, &b); getchar(); while (a < b) { c = a*a; d = b*b; for (int n = a; n <= b; n++) { sum = sum + n*n; } printf("The sume of the squares from %d to %d is %d ", c, d, sum); printf("Enter next set of limits:"); sum = 0; scanf("%d,%d", &a, &b); getchar(); } printf("Done!!!"); getchar(); return 0; }
11、
#include <stdio.h> #include <string> int main() { int in[8] = { 0 }; for (int i = 0; i < 8; i++) { printf("请输入%d个整数:",i+1); scanf("%d", &in[i]); getchar(); } printf("倒序为 "); for (int i = 7; i >= 0; i--) { printf("%d", in[i]); } getchar(); return 0; }
12、
13、
#include <stdio.h> #include <string> int main() { int i = 0; int in[8] = { 0 }; for (i = 1; i < 8; i++) { in[0] = 2; in[i] = in[i - 1]*2; } i = 0; do { printf("%d ", in[i]); i++; } while (i<8); getchar(); return 0; }
14、 由于输入的位数可能不一样,并没能做到每一个元素完全对应
#include <stdio.h> #include <string> int main() { double in_1[8] = { 0 }; double in_2[8] = { 0 }; for (int i = 0; i < 8; i++) { scanf("%lf", &in_1[i]); getchar(); in_2[0] = in_1[0]; if(i>0) in_2[i] = in_1[i] + in_2[i-1]; } for (int i = 0; i < 8; i++) { printf("%lf", in_1[i]); printf(" "); } printf(" "); for (int i = 0; i < 8; i++) { printf("%lf", in_2[i]); printf(" "); } getchar(); return 0; }
15、
#include <stdio.h> #include <string> int main() { char in_1[255] = { 0 }; scanf("%s", &in_1); getchar(); int len = strlen(in_1); printf("%s ", in_1); for (int i = len-1; i >=0; i--) { printf("%c", in_1[i]); } getchar(); return 0; }
16、
#include <stdio.h> #include <string> int main() { int year = 0; double daphne = 100; double deirdre = 100; do { year++; daphne = daphne + 10; deirdre = 1.05*deirdre; } while (deirdre <= daphne); printf("在第%d年后,daphne的投资额为%f,deirdre的投资额为%f",year,daphne,deirdre ); getchar(); return 0; }
17、
#include <stdio.h> #include <string> int main() { int year = 0; double money = 100; do { year++; money = money*1.08 - 10; } while (money > 0); printf("在第%d年后,钱用完了",year ); getchar(); return 0; }
18、
#include <stdio.h> #include <string> int main() { int i = 0; int n = 5; do { i++; n = n - i; n = n*2; printf("博士第%d周的时候有朋友%d人 ", i, n); } while (n <= 150); getchar(); return 0; }