第三章编程练习

*爱你&永不变心* 提交于 2020-11-24 02:21:17

第二题

#include<stdio.h>
int main()
{
    int input;
    printf("Enter a value of char int ASCII:");
    scanf("%d",&input);

    printf("You input value is %d,and char is %c\n",input,input);

    return 0;
}

第三题

#include<stdio.h>
int main()
{
    char ch = '\a';
    printf("%c",ch);

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

第四题

#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;
}

第五题

#include<stdio.h>
#define SEC_PER_YEAR 3.156e7
int main()
{
    float second,year;
    printf("Enter how many years old you are:");
    scanf("%f",&year);
    second = year*SEC_PER_YEAR;
    printf("You are: %.1f year old.\n",year);
    printf("And you are %e seconds old, too.\n",second);
    
    return 0;
}

第六题

#include<stdio.h>
#define MASS_PER_MOLE 3.0E-23
#define MASS_PER_QUART 950
int main()
{
    float quart,quantify;
    printf("Enter how many quart:");
    scanf("%f",&quart);
    quantify = quart*MASS_PER_QUART/MASS_PER_MOLE;
    printf("There are %e molecule.\n",quantify);

    return 0;  
}

第七题

#include<stdio.h>
#define INCH_TO_CM 2.54
int main()
{
    float inch,cm;
    scanf("%f",&inch);
    cm = inch*INCH_TO_CM;

    printf("Hi ,your are %0.2f inch ,or %0.2f cm heigh\n",inch,cm);

    return 0;
}

第八题

#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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!