书本作业2到5章

荒凉一梦 提交于 2020-11-15 23:52:51

2-1

*
 * @Author: 徐博凡
 * @Date: 2020-11-08 22:57:31
 * @LastEditTime: 2020-11-08 23:01:02
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinedc:\Users\xbf77\Desktop\C\书本作业\2-1.c
 */
#include<stdio.h>
int main()
{
    printf("徐博凡\n");
    printf("徐\n");
    printf("博凡\n");
    printf("徐博凡");
    printf("徐博凡");

    getchar();
    return 0;
}

2-2

/*
 * @Author: 徐博凡
 * @Date: 2020-11-08 23:05:25
 * @LastEditTime: 2020-11-08 23:06:07
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \undefinedc:\Users\xbf77\Desktop\C\书本作业\2-2.c
 */
#include<stdio.h>
int main()
{
    printf("徐博凡\n");
    printf("浙江树人大学致和园");

    getchar ();
    return 0;
}

2-3

/*
 * @Author: 徐博凡
 * @Date: 2020-11-08 23:06:24
 * @LastEditTime: 2020-11-08 23:27:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedc:\Users\xbf77\Desktop\C\书本作业\2-3.c
 */
#include<stdio.h>
#define days 365
int main()
{
    int age,day;
    age=19;
    day=age*days;
    printf("你的年龄为%d,天数为%d",age,day);

    getchar();
    return 0;
}

2-4

/*
 * @Author: 徐博凡
 * @Date: 2020-11-08 23:27:50
 * @LastEditTime: 2020-11-08 23:36:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedc:\Users\xbf77\Desktop\C\书本作业\2-4.c
 */
#include<stdio.h>
int jolly();
int deny();
int main()
{
    jolly();
    jolly();
    jolly();
    deny();

    return 0;
}
int jolly()
{
    printf("For he's a jolly good fellow!\n");
    return 0;
}
int deny()
{
    printf("Which nobody can deny!\n");
    return 0;
}    

2-5

/*
 * @Author: your name
 * @Date: 2020-11-10 18:32:07
 * @LastEditTime: 2020-11-10 18:41:01
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\2-5.c
 */
#include<stdio.h>
int br();
int ic();
int main()
{
    br();
    printf(",");
    ic();
    ic();
    br();
    return 0;
}
int br()
{
    printf("Brazil,Russia");
    return 0;
}
int ic()
{
    printf("India,China\n");
    return 0;
}

2-6

/*
 * @Author: your name
 * @Date: 2020-11-12 22:15:32
 * @LastEditTime: 2020-11-12 22:30:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\2-6.c
 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int toes;
    toes=10;
    printf("toes=%d\n",toes);
    toes=2*toes;
    printf("double toes=%d\n",toes);
    toes=pow(toes/2,2);
    printf("toes square=%d\n",toes);

    system("pause");
    return 0;
}

2-7

/*
 * @Author: your name
 * @Date: 2020-11-12 22:31:45
 * @LastEditTime: 2020-11-12 22:43:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\2-7.c
 */
#include<stdio.h>
int s();
int main()
{
    s();s();s();
    printf("\n");
    s();s();
    printf("\n");
    s();

    getchar();
    return 0;
}
int s()
{
    printf("Smile!");
    return 0;
}

2-8

/*
 * @Author: your name
 * @Date: 2020-11-12 22:40:42
 * @LastEditTime: 2020-11-12 22:57:37
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\2-8.c
 */
#include<stdio.h>
int one_three();
int two();
int main()
{
    printf("starting now:\n");
    one_three();
    printf("done!\n");

    getchar();
    return 0;
}
int one_three()
{
    printf("one\n");
    two();
    printf("three\n");

    return 0;
}
int two()
{
    printf("two\n");

    return 0;
}

3-2

/*
 * @Author: your name
 * @Date: 2020-11-12 22:56:52
 * @LastEditTime: 2020-11-12 23:16:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\3-2.c
 */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x;
    printf("输入一个ASCII码:");
    scanf("%d",&x);

    printf("输出的字符为%c\n",x);

    system("pause");
    return 0;
}

3-3

/*
 * @Author: your name
 * @Date: 2020-11-12 23:16:54
 * @LastEditTime: 2020-11-12 23:19:58
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\3-3.c
 */
#include<stdio.h>
int main()
{
    char ch = '\a';
    printf("%c",ch);

    printf("Starled by the sudden sound,Sally shouted,\n");
    printf("\"By the Great Pumpkin,what was that!\"\n");

    getchar ();
    return 0;
}

3-4

/*
 * @Author: your name
 * @Date: 2020-11-13 23:58:09
 * @LastEditTime: 2020-11-14 00:01:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\3-4.c
 */
#include<stdio.h>
int main()
{
    float input;
    printf("Enter a floating-point value:");
    scanf("%f",&input);
    printf("fixed-point notation:%f\n",input);
    printf("exponential notation:%e\n",input);
    printf("p notation:%a\n",input);

    return 0;
}

3-5

/*
 * @Author: your name
 * @Date: 2020-11-14 10:53:47
 * @LastEditTime: 2020-11-14 10:58:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\3-5.c
 */
#include<stdio.h>
#define S_P_Y 3.156e7
int main()
{
    float second,year;
    printf("Enter how many year old you are:");
    scanf("%f",&year);
    second=year*S_P_Y;
    printf("You are:%.1f years old.\n",year);
    printf("And you are %e sconds old,too.\n",second);
    return 0;
}

3-6

/*
 * @Author: your name
 * @Date: 2020-11-14 10:58:50
 * @LastEditTime: 2020-11-14 11:02:05
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\3-6.c
 */
#include<stdio.h>
#define MOLE 3.0e-23
#define QUART 950
int main()
{
    float quart,quantity;
    printf("Enter how many quart:");
    scanf("%f",&quart);
    quantity=quart*QUART/MOLE;
    printf("There are %e molecule.\n",quantity);
    return 0;
}

3-7

/*
 * @Author: your name
 * @Date: 2020-11-14 11:02:44
 * @LastEditTime: 2020-11-14 11:05:13
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\3-7.c
 */
#include<stdio.h>
#define INCH_TO_CM 2.54
int main()
{
    float inch,cm;
    printf("Enter the inch of your heigh:");
    scanf("%f",&inch);
    cm=inch*INCH_TO_CM;
    printf("Hi,your are %0.2f inch,or %.2f cm heigh\n",inch,cm);
    return 0;
}

3-8

/*
 * @Author: your name
 * @Date: 2020-11-14 11:05:52
 * @LastEditTime: 2020-11-14 11:14:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\3-8.c
 */
#include<stdio.h>
#define PINT_CUP 2
#define CUP_OUNCE 8
#define OUNCE_SPOON 2
#define SPOON_TEA 3
int main()
{
    float pint,cup,ounce,spoon,tea_spoon;
    printf("Enter how many cup:");
    scanf("%f",&cup);
    pint=cup/PINT_CUP;
    ounce=cup*CUP_OUNCE;
    spoon=ounce*OUNCE_SPOON;
    tea_spoon=spoon*SPOON_TEA;

    printf("%.1f cup equals %.1f pint,%.1f ounce,%.1f spoon,%.1f tea_spoon.\n",cup,pint,ounce,spoon,tea_spoon);
    return 0;
}

4-1

/*
 * @Author: your name
 * @Date: 2020-11-14 11:17:23
 * @LastEditTime: 2020-11-14 11:22:45
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\zhuomian\C\4-1.c
 */
#include<stdio.h>
int main()
{
    char name[40];
    char surname[40];
    printf("Please input your first name:");
    scanf("%s",&name);
    printf("Please input your last name:");
    scanf("%s",&surname);
    printf("Hello,%s,%s.",name,surname);
    return 0;
}

4-2

/*
 * @Author: your name
 * @Date: 2020-11-15 20:11:19
 * @LastEditTime: 2020-11-15 20:22:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-2.c
 */
#include<stdio.h>
int main()
{
    char name[40];
    int width;
    printf("Please input your name:");
    scanf("%s",name);
    width=printf("\"%s\"\n.",name);
    width -=4;
    printf("\"%20s\".\n",name);
    printf("\"%*s\".",(width+3),name);

    return 0;
}

4-3

/*
 * @Author: your name
 * @Date: 2020-11-15 20:23:03
 * @LastEditTime: 2020-11-15 20:24:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-3.c
 */
#include<stdio.h>
int main()
{
    float input;
    printf("Enter a float number:");
    scanf("%f",&input);
    printf("The input is %.1f or %.1e\n",input,input);
    return 0;
}

4-4

/*
 * @Author: your name
 * @Date: 2020-11-15 20:24:56
 * @LastEditTime: 2020-11-15 20:29:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-4.c
 */
#include<stdio.h>
int main()
{
    float heigh;
    char name[40];
    printf("Enter your name:");
    scanf("%s",name);
    printf("Hi %s,how tall you are( inch ):",name);
    scanf("%f",&heigh);
    printf("%s,you are %.3f feet tall\n",name,heigh/12.0);
    return 0;
}

4-5

/*
 * @Author: your name
 * @Date: 2020-11-15 20:30:08
 * @LastEditTime: 2020-11-15 20:33:38
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-5.c
 */
#include<stdio.h>
int main()
{
    float speed,size,time;
    printf("Pleast input the net speed(megabits per second):");
    scanf("%f",&speed);
    printf("Pleast input the file size(megabyte):");
    scanf("%f",&size);
    time = size*8/speed;
    printf("At %.2f megabits per second,a file of %.2f megabytes download in %.2f seconds.",speed,size,time);
    return 0;
}

4-6

/*
 * @Author: your name
 * @Date: 2020-11-15 20:33:58
 * @LastEditTime: 2020-11-15 20:44:19
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-6.c
 */
#include<stdio.h>
int main()
{
    char name[40],surname[40];
    int wname,wsurname;
    printf("Please input your first name:");
    scanf("%s",name);
    printf("Please input your last name:");
    scanf("%s",surname);
    wname=printf("%s",name);
    printf("");
    wsurname=printf("%s",surname);
    printf("\n%*d %*d",wname,wname,wsurname,wsurname);
    return 0;
}

4-7

/*
 * @Author: your name
 * @Date: 2020-11-15 20:44:41
 * @LastEditTime: 2020-11-15 20:49:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-7.c
 */
#include<stdio.h>
#include<float.h>
int main()
{
    double d_third=1.0/3.0;
    float f_third=1.0/3.0;
    printf("float of one third(6)=%.6f\n",f_third);
    printf("float of one third(12)=%.12f\n",f_third);
    printf("float of one third(16)=%.16f\n",f_third);
    printf("float of one third(6)=%.6lf\n",d_third);
    printf("float of one third(12)=%.12lf\n",d_third);
    printf("float of one third(16)=%.16lf\n",d_third);
    printf("FLT_DIG in float.h is %d\n",FLT_DIG);
    printf("DBL_DIG in float.h is %d\n",DBL_DIG);

    return 0;
}

4-8

/*
 * @Author: your name
 * @Date: 2020-11-15 20:50:02
 * @LastEditTime: 2020-11-15 20:54:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\4-8.c
 */
#include<stdio.h>
#define GALLON_TO_LITRE 3.785
#define MILE_TO_KM 1.609
int main()
{
    float range,oil;
    printf("Pleast input the range you traveled(in mile):");
    scanf("%f",&range);
    printf("Pleast input the oil you spend(in gallon):");
    scanf("%f",&oil);
    printf("In UAS,your oil wear is %.1f M/G\n",range/oil);
    printf("In Europe,your oil wear is %.1fL/100KM",(oil*GALLON_TO_LITRE)/(range*MILE_TO_KM));

    return 0;
}

5-1

/*
 * @Author: your name
 * @Date: 2020-11-15 21:50:53
 * @LastEditTime: 2020-11-15 21:50:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-1.c
 */
#include<stdio.h>
#define MIN_PER_HOU 60
int main(int argc, char *argv[])
{
    int hours, minutes, input;
    printf("CONVERT MINUTES TO HOURS!\n");
    printf("PLEASE INPUT THE NUMBER OF MINUTES( <=0 TO QUIT ):");
    scanf("%d",&input);
    while(input >0){
        hours = input/MIN_PER_HOU;
        minutes = input%MIN_PER_HOU;
        printf("CONVER TO %d HOUR AND %d MINUTES\n",hours,minutes);
        printf("PLEASE COMTINUE INPUT THE MUNMBER OF MINUTES( <=0 TO QUIT ):");
        scanf("%d",&input);
    }
    printf("PROGRAM EXIT!\n");
}

5-2

/*
 * @Author: your name
 * @Date: 2020-11-15 21:51:09
 * @LastEditTime: 2020-11-15 21:58:14
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-2.c
 */
#include<stdio.h>
int main(int argc, char *argv[])
{
    int counter, i = 0;
    printf("PRINT COUNTINUE 10 NUMBERS!\n");
    printf("PLEAE IPUT THE START NUMBER :");
    scanf("%d",&counter);
    while(i++ < 11){
        printf(" %d \n",counter++);
    }
    printf("PROGRAM EXIT!\n");
    return 0;
}

5-3

/*
 * @Author: your name
 * @Date: 2020-11-15 21:51:44
 * @LastEditTime: 2020-11-15 21:57:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-3.c
 */
#include<stdio.h>
#define WEEK_PER_DAY 7
int main(int argc, char *argv[])
{
int days, weeks, input;
printf("CONVERT DAYS TO WEEKS!\n");
printf("PLEASE INPUT THE OF NUMBER OF DAYS( <=0 TO QUIT ):");
scanf("%d",&input);
while(input > 0){
    weeks = input/WEEK_PER_DAY;
    days = input%WEEK_PER_DAY;
    printf("%d days are %d weeks, %d days\n",input,weeks,days);
    printf("PLEASE INPUT THE NUMBER OF DAYS( <=0 TO QUIT ):");
    scanf("%d,&input");
}
printf("PROGRAM EXIT!\n");
return 0;
}

5-4

/*
 * @Author: your name
 * @Date: 2020-11-15 21:52:07
 * @LastEditTime: 2020-11-15 21:55:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-4.c
 */
#include<stdio.h>
#define FEET_TO_CM 30.48
#define INCH_TO_CM 2.54
int main(int argc,char *argv[])
{
int feet;
float inches, cm;
printf("CONVERT CM TO INCHES!\n");
printf("'Enter the height in centimeters:");
scanf("%f",&cm);
while(cm > 0)
{
    feet + cm/FEET_TO_CM;
    inches = (cm - feet*FEET_TO_CM)/INCH_TO_CM;
    printf("%.1f cm = %d feet , %.1f inches\n",cm,feet,inches);
    printf("Enter the height in centimeters( <=0 TO QUIT ):");
    scanf("%f",&cm);
}
    printf("PROGRAM EXIT!\n");
    return 0;
}

5-5

/*
 * @Author: your name
 * @Date: 2020-11-15 22:10:44
 * @LastEditTime: 2020-11-15 22:11:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-5.c
 */
#include<stdio.h>
int main(int argc, char *argv[])
{
    int count = 0, sum = 0;
    printf("Enter the nember of days you work:");
    scanf("%d",&count);
    while(count > 0)
    {
        sum = sum + count--;
    }
    printf("You earned $ %d total!\n",sum);
    printf("PROGRAM EXIT!\n");
    return 0;
}

5-6

/*
 * @Author: your name
 * @Date: 2020-11-15 21:56:03
 * @LastEditTime: 2020-11-15 21:57:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-5.c
 */
#include<stdio.h>
int main(int argc, char *argv[])
{
    int count = 0, sum = 0 ;
    printf("Enter the number of days you work:");
    scanf("%d",&count);
    while(count > 0){
        sum = sum + count * count;
        count--;
    }
    printf("You earned $ %d total!\n",sum);
    printf("PROGRAM EXIT!\n");
    return 0;
}

5-7

/*
 * @Author: your name
 * @Date: 2020-11-15 21:59:33
 * @LastEditTime: 2020-11-15 22:10:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-7.c
 */
#include<stdio.h>
double cubic(double n);
int main(int argc, char *argv[])
{
    double input;
    printf("Enter the double to calc cubic :");
    scanf("%1f",&input);
    printf("PROGRAM EXIT!\n");
    return 0;
}
double cubic(double n)
{
    double t = n * n * n;
    printf("The %lg's cubic is %lg !\n",n,t);;
    return 0;
}

5-8

/*
 * @Author: your name
 * @Date: 2020-11-15 22:02:43
 * @LastEditTime: 2020-11-15 22:03:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-8.c
 */
#include<stdio.h>
int main(int argc, char *argv[])
{
    int first,second;
    printf("This program computes moduli.\n");
    printf("Enter an integer to server as the second operand:");
    scanf("%d",&second);
    while(first > 0){
        printf("%d %% %d is %d\n",first,second,(first%second));
        printf("Enter next number for first operand( <= 0 to quit):");
        scanf("%d",&first);
    }
    printf("Done!\n");
    return 0;
}

5-9

/*
 * @Author: your name
 * @Date: 2020-11-15 22:00:06
 * @LastEditTime: 2020-11-15 22:02:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinedx:\C\书本作业\5-8.c
 */
#include<stdio.h>
int Temperatures(double fahrenheit);
int main(int argc,char *argv[])
{
    double input;
    printf("This program convert fahrenheit to celsius and kelvin.\n");
    printf("Enter a fahrenheit to start :");
    while(scanf("%1f",&input) == 1){
        Temperatures(input);
        printf("Enter next fahrenheit! ( q to quit): ");
    }
    printf("Done!\n");
    return 0;
}
int Temperatures(double fahrenheit)
{
    const double F_TO_C = 32.0;
    const double C_TO_K = 273.16;
    double celsius ,kelvin;
    celsius = 5.0/9.0*(fahrenheit - F_TO_C);
    kelvin = celsius + C_TO_K;
    printf("%.2f. fahrenheit, equal %.2f celsius,and %.sf kelvin\n",fahrenheit, celsius,kelvin);
    return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!