• 135235

    文章

  • 827

    评论

  • 13

    友链

  • 最近新加了换肤功能,大家多来逛逛吧~~~~
  • 喜欢这个网站的朋友可以加一下QQ群,我们一起交流技术。

书本作业第六章

2年想跳槽阿里,大咖揭秘大厂面试的那些事儿 >>

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 10:25:20
  • @LastEditTime: 2020-11-22 10:36:13
  • @LastEditors: Please set LastEditors
  • @Description: 创建一个包含26个元素的数组,并存储26个小写字母,打印。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\1.c */
int main() {
    char alphabet [26];
    int i;
    char c = 'a';
    /*定义变量i为数组的下标,c从字符a开始递增,
     *获得26个字母*/
    for (i = 0; i<26 ;i++,c++)
        alphabet [i] = c;
        /*for循环的更新部分,更新了下标和字母表*/
    for (i = 0;i <26 ; i++)
        printf("%c ",alphabet [i]);
    return 0;        
}

/*

  • @Author:潘振宇
  • @Date: 2020-11-22 10:33:13
  • @LastEditTime: 2020-11-22 10:36:40
  • @LastEditors: Please set LastEditors
  • @Description: $小循环
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\2.c
#include<stdio.h>

int main() {
    int i,j;
    for (i = 1; i<=5 ;i++){
        /*外层循环控制行数*/
        for (j = 0 ; j< i ;j++)
        /*内层循环使用j<表示第N行打印N个字符*/
        printf("$");
    printf("\n");
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 10:36:51
  • @LastEditTime: 2020-11-22 10:44:38
  • @LastEditors: Please set LastEditors
  • @Description: 嵌套循环F-A倒打印
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\3.c */

int main() {
    int i,j;
    char c;
    for(i = 1;j <= 6; i++){
        for (j = 0, c = 'F'; j < i ; j++,c--)
            printf("%c",c);
        printf("\n");
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 10:44:49
  • @LastEditTime: 2020-11-22 10:48:26
  • @LastEditors: Please set LastEditors
  • @Description:A开始,每行递增,6行
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\4.c
#include<stdio.h>

int main() {
   int i,j;
   char c = 'A';
   for (i = 1; i<=6;i++){
       for (j = 0; j<i ; j++,c++)
           printf("%c",c);
       printf("\n");
   }
   return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 10:48:35
  • @LastEditTime: 2020-11-22 11:05:10
  • @LastEditors: Please set LastEditors
  • @Description: A ABA 打印5行
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\5.c */

int main() {
    int i ,j,num;
    char c ;
    printf("Enter the core char you want to printf(A...Z):");
    scanf("%c",&c);
    char ch = 'A';
    num = c- 'A' + 1;

    for(i = 1;i <= num; i++) {
        for (j = 0;j< num - i ; j++)
           printf(" ");
        for (ch = 'A'; j < num ;j++)
           printf("%c",ch++);
        for (j = 1, ch-=2;j < i ; j++,ch--)
           printf("%c",ch);
           printf("\n");
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 10:48:35
  • @LastEditTime: 2020-11-22 11:05:10
  • @LastEditors: Please set LastEditors
  • @Description: A ABA 打印5行
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\5.c */

int main() {
    int i ,j,num;
    char c ;
    printf("Enter the core char you want to printf(A...Z):");
    scanf("%c",&c);
    char ch = 'A';
    num = c- 'A' + 1;

    for(i = 1;i <= num; i++) {
        for (j = 0;j< num - i ; j++)
           printf(" ");
        for (ch = 'A'; j < num ;j++)
           printf("%c",ch++);
        for (j = 1, ch-=2;j < i ; j++,ch--)
           printf("%c",ch);
           printf("\n");
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:05:22
  • @LastEditTime: 2020-11-22 11:11:38
  • @LastEditors: Please set LastEditors
  • @Description: 使用for循环,每一行打印一个整数,该数的平方、立方,输入上下限
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\6.c
#include<stdio.h>

int main() {
    int start,end;
    printf("Please enter the start number:");
    scanf("%d",&start);
    printf("Please enter the end number:");
    scanf("%d",&end);

    printf("    Ori:    Square:    Cubic:\n");
    for (int i = start;i <=end ;i++) {
        printf("%6d,%10d,%10d",i,i*i,i*i*i);
        printf("\n");
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:11:58
  • @LastEditTime: 2020-11-22 11:34:13
  • @LastEditors: Please set LastEditors
  • @Description:把一个单词读入一个字符数组中,倒序打印
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\7.c */
#include<string.h>

int main() {
    char word[30];
    printf("Please enter the words: ");
    printf("The word you enter is : %s\n",word);
    printf("The reverse word you enter is :");
    printf("%d",strlen(word));
    for (int i = strlen(word) -1;i >= 0 ; i--){
        printf("%c",word[i]);
    }
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:34:22
  • @LastEditTime: 2020-11-22 11:40:21
  • @LastEditors: Please set LastEditors
  • @Description: 要求用户输入两个浮点数,打印两数之差除以两数之积。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\8.c */

int main() {
    float x,y;
    printf("Please enter the two foloat data(seprate by blank):");
    while(scanf("%f %f",&x,&y) ==2) {
        printf("The answer is %f\n",(x-y)/(x*y));
        printf("Please enter the two foloat data(seprate bt blank):");
    }
    printf("Program end!");
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:41:10
  • @LastEditTime: 2020-11-22 11:43:17
  • @LastEditors: Please set LastEditors
  • @Description:修改练习8,使用一个函数返回计算结果
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\9.c */

float calc(float x,float y);
int main() {
    float x,y;
    printf("Please enter the two foloat data(seprate by blank):");
    while(scanf("%f %f",&x,&y) ==2) {
        printf("The answer is %f\n",(x-y)/(x*y));
        printf("Please enter the two foloat data(seprate bt blank):");
    }
    printf("Program end!");
    return 0;
}
float calc(float x, float y){
    float result;
    result = (x-y)/(x*y);
    return result;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:45:05
  • @LastEditTime: 2020-11-22 11:52:41
  • @LastEditors: Please set LastEditors
  • @Description: 要求用户输入一个上限整数和一个下限整数,计算所有整数的平方和,并显示结果。在提示输入,知道上下限相等
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\10.c */
int main() {
    int lower,upper;
    printf("Enter lower and upper integer limits:");
    scanf("%d %d",&lower,&upper);

    while(upper > lower){
        int sum =0;
        for (int i =lower;i <=upper; i++){
            sum = sum + i*i;
        }
        printf("The sum of the squares form %d to %d is %d\n",lower,upper,sum);
        printf("Enter lower and upper interer limits:");
        scanf("%d %d",&lower,&upper);
    }
    printf("Done!");
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 11:53:01
  • @LastEditTime: 2020-11-22 11:53:02
  • @LastEditors: Please set LastEditors
  • @Description: 在数组中读入八个整数,然后倒序打印
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\11.c */
int main(){
    int data[8];
    printf("Enter the 8 integer data (seperate by blank):");
    for (int i= 0;i < 8;i++){
        scanf("%d",&data[i]);
    }

    printf("Ok, the reverse data is :");
    for(int i=0;i < 8;i++){
        printf(" %d",data[i]);
    }
    printf("\nDone!\n");
    return 0;
}

/*

  • @Author: 潘振宇
  • @LastEditTime: 2020-11-22 12:10:08
  • @LastEditors: Please set LastEditors
  • @Description: 第六章第12题 难得一比
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\12.c */
int main() {
    int length;
    double sum = 0.0;
    printf("Enter the limit length: ");
    scanf("%d",&length);
    while(length>0){
        sum = 0.0;
        for(int i=1;i <=length; i++){
            sum = sum +1.0/i;
        }
        printf("The sum for 1.0+...+ 1.0/%d.0 is %1f\n",length,sum);
        sum=0.0;
        for(int i= 1;i <= length;i++){
            if(i%2==0) sum = sum -1.0/i;
            else sum = sum + 1.0/i;
        }
        printf("The sum for 1.0+ 1.0+2.0/3.0+...+2.0/%d.0 is %1f\n",length,sum);

        printf("Enter the limit length:");
        scanf("%d",length);
    }
    printf("\nDone!\n");
    return 0;
}

/*

  • @Author:潘振宇
  • @Date: 2020-11-22 12:10:15
  • @LastEditTime: 2020-11-22 12:14:16
  • @LastEditors: Please set LastEditors
  • @Description:创建一个包含8个元素的int类型数组,分别把数组元素设置为2的前8次幂,使用for循环设置数组元素的值,用do。。。with循环。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\13.c */
int main() {
    int data[8];
    data[0] = 2;

    for(int i= 1; i < 8 ;i++){
        data[i] = data[i-1] * 2;
    }
    int i = 0;
    do{
        printf("%d ",data[i++]);
    }while(i<8);

    printf("\nDone!\n");
    return 0;
}

/*

  • @Author:潘振宇
  • @Date: 2020-11-22 12:14:24
  • @LastEditTime: 2020-11-22 12:22:41
  • @LastEditors: Please set LastEditors
  • @Description: 创建两个包含8个元素的double类型数组,使用循环提示用户为第一个数组输入8个值。第二个数组元素的值设置为第一个数组对应元素的累加和。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\14.c */

int main() {
    double first[8], second[8];
    printf("Enter 8 data to the FIRST array: ");
    for(int i = 0; i < 8;i++){
        scanf("%1f",&first[i]);
    }
    for (int i = 0; i < 8;i++){
        double sum = 0;
        for(int j = 0; j<=i;j++){
           sum =sum +first[j];
        }
        second[i] = sum;
    }
    printf("All the data of two array:\n");
    printf("First Array:");
    for(int i = 0; i<8;i++){
        printf("%121f. ",first[i]);
    }
    printf("\nSecond Array: ");
    for(int i = 0;i < 8;i++){
        printf("%121f. ",second[i]);
    }

    printf("\nDone!\n");
    return 0;
}

/*

  • @Author:潘振宇
  • @Date: 2020-11-22 12:22:49
  • @LastEditTime: 2020-11-22 12:27:38
  • @LastEditors: Please set LastEditors
  • @Description:读取一行输入,然后把输入的内容倒序打印出来。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\16.c */
#include<string.h>
int main() {
    char data[256];
    printf("Enter the char in aline : ");
    int i = 0;
    do{
        scanf("%c",&data[i]);
    }while(data[i]!='\n' && ++i);

    printf("The reverse char of the data: ");
    for(i--;i >=0;i--){
        printf("%c",data[i]);
    }
    printf("\nDone!\n");
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 12:27:49
  • @LastEditTime: 2020-11-22 12:32:18
  • @LastEditors: Please set LastEditors
  • @Description:第六章16题,单利与复利的比较
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\16.c */
#include<string.h>
int main() {
    float dephne,deirdre;
    daphne = deirdre = 100.0;
    int year = 0;
    do{
        dephne = daphne + 100*0.1;
        deirdre = deirdre + deirdre*0.05;
        year++;
    }while((deirdre - daphne) < 0);

    printf("%d years later.\nDaphne = %f.\nDeirdre= %f \n",year,daphne,deirdre);
    printf("\nDone!\n");
    return 0;
}

/*

  • @Author:潘振宇
  • @Date: 2020-11-22 12:32:28
  • @LastEditTime: 2020-11-22 12:37:03
  • @LastEditors: Please set LastEditors
  • @Description:CL赢得了100万美元,把钱存入年利率为8%的账户中。在每年的最后一天他取出10万美元,若余额低于9万美元,则不够下一年取出。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\17.c */
#include<string.h>
int main() {
    float CL= 100;
    int year = 0;
    do{
        CL = CL + CL*0.08;
        CL -= 10;
        year++;
        printf("%f\n",CL);
    }while(CL > 9);

    printf("%d years later. CL's account %f \n",year,CL);
    printf("%d tears later. CL's account is full \n",++year);
    printf("\nDone!\n");
    return 0;
}

/*

  • @Author: 潘振宇
  • @Date: 2020-11-22 12:37:10
  • @LastEditTime: 2020-11-22 12:40:33
  • @LastEditors: Please set LastEditors
  • @Description: R博士发现 起初他有5个朋友,每周减一个但是剩下的翻倍了,超过150停止。
  • @FilePath: \undefinedc:\Users\潘振宇\Desktop\代码\书本作业第6章\18.c */
#include<string.h>
int main() {
    int R = 5;
    int weeks =1;
    while(R < 150){
        printf("At %d weeks,R has %4d friends \n",weeks,R);
        R=2*(R-weeks++);
    };
    printf("\nDone!\n");
    return 0;
}

695856371Web网页设计师②群 | 喜欢本站的朋友可以收藏本站,或者加入我们大家一起来交流技术!

0条评论

Loading...


发表评论

电子邮件地址不会被公开。 必填项已用*标注

自定义皮肤 主体内容背景
打开支付宝扫码付款购买视频教程
遇到问题联系客服QQ:419400980
注册梁钟霖个人博客