#include<stdio.h>intmain(void){char letter[26];
letter[0]='a';for(int i =1; i <26; i++){
letter[i]= letter[i -1]+1;}for(int i =0; i <26; i++){printf("%c", letter[i]);}return0;}
6-2
#include<stdio.h>intmain(void){for(int i =1; i <6; i++){for(int j =1; j <= i; j++){printf("$");}printf("\n");}return0;}
6-3
#include<stdio.h>intmain(void){int i, j;for(i =1; i <=6; i++){for(char f ='F', j =0; j < i; j++,f--){//f = f - 1;printf("%c", f);}printf("\n");}return0;}
6-4
#include<stdio.h>intmain(void){int i, j;char a ='A';for(i =1; i <=6; i++){for(j =0; j < i; j++,a++){printf("%c", a);}printf("\n");}return0;}
6-5
#include<stdio.h>#defineA'A'intmain(void){char ch;char tem;printf("请输入一个大写字母:");scanf("%c",&ch);int row = ch - A +1;for(int i =1; i <= row; i++){//char tem;for(int j =0; j < row - i; j++){//左边的空格printf(" ");}for(int j =0; j < i; j++){//左边的字母
tem = A + j;printf("%c", tem);}for(int j =1; j < i; j++){//右边的字母
tem = tem -1;printf("%c", tem);}printf("\n");}return0;}
6-6
#include<stdio.h>intmain(void){int min_num, max_num;/*printf("请输入表格的上下限:");
scanf("%d%d", &max_num, &min_num);*/printf("请输入表格的上限(最大值):");scanf("%d",&max_num);printf("请输入表格的下限(最小值):");scanf("%d",&min_num);for(int i = min_num; i <= max_num; i++){printf("%d\t%d\t%d\n", i, i * i, i * i * i);}return0;}
6-7
#include<stdio.h>#include<string.h>intmain(void){char str[20];int sz;printf("请输入一个单词:");scanf("%s", str);//scanf无法接收带空格的字符串
sz =strlen(str);for(int i = sz -1; i >=0; i--){printf("%c", str[i]);}return0;}
6-8
#include<stdio.h>intmain(void){float f1, f2;printf("请输入两个浮点数:");int ret =scanf("%f %f",&f1,&f2);while(ret ==2){printf("两数之差/两数乘积 = %f\n",(f1 - f2)/(f1 * f2));printf("请输入两个浮点数(输入q退出程序):");
ret =scanf("%f %f",&f1,&f2);}printf("Done!");return0;}
6-9
#include<stdio.h>floatCum(float f1,float f2);intmain(void){float f1, f2;printf("请输入两个浮点数:");int ret =scanf("%f %f",&f1,&f2);while(ret ==2){printf("两数之差/两数乘积 = %f\n",Cum(f1,f2));printf("请输入两个浮点数(输入q退出程序):");
ret =scanf("%f %f",&f1,&f2);}printf("Done!");return0;}floatCum(float f1,float f2){float res =(f1 - f2)/(f1 * f2);return res;}
6-10
#include<stdio.h>intmain(void){int min_num, max_num;printf("Enter lower and upper integer limits:");scanf("%d %d",&min_num,&max_num);while(max_num > min_num){int sum =0;//不要忘记初始化!for(int i = min_num; i <= max_num; i++){
sum = i * i + sum;}printf("The sums of the squares from %d to %d is %d\n", min_num * min_num, max_num * max_num, sum);printf("Enter next set of limits:");scanf("%d %d",&min_num,&max_num);}printf("Done!");return0;}
6-11
#include<stdio.h>intmain(void){int num[8];printf("请输入8个整数:");for(int i =0; i <8; i++){scanf("%d",&num[i]);}for(int j =0; j <8; j++){printf("%d\t", num[7- j]);}return0;}
#include<stdio.h>intmain(void){int num[8];
num[0]=2;int j =0;for(int i =1; i <8; i++){
num[i]=2* num[i -1];}do{printf("%d\t", num[j]);
j++;}while(j <8);return0;}
6-14
#include<stdio.h>intmain(void){double num[8];double sum[8];int sum8 =0;printf("请输入8个数:");for(int i =0; i <8; i++){scanf("%lf",&num[i]);}for(int j =0; j <8; j++){
sum8 = sum8 + num[j];
sum[j]= sum8;}for(int i =0; i <8; i++){printf("%lf\t", num[i]);}printf("\n");for(int i =0; i <8; i++){printf("%lf\t", sum[i]);}return0;}
6-15
#include<stdio.h>#include<string.h>intmain(void){char input[256];printf("请输入一行字符串:");int i =0;do{scanf("%c",&input[i]);}while(input[i]!='\n'&&++i);//此时结束i下标为最后一个\n处for(--i; i >=0; i--){//让i先落到字符串最后一个字符处printf("%c", input[i]);}return0;}