这是6.13的练习哦~

今天的主要练习~
1.编写一个程序,要求提示输入一个ASCII码值(如,66),然后打印输入的字符。

#include <stdio.h>
int main()
{
    char i;
    printf("请输入一个ASII码的值:\n");
    scanf("%d",&i);
    printf("打印的%d字符为:%c\n",i,i);
    return 0;
}

2.一年大约有3.156*10^7秒。编写一个程序,提示用户输入年龄,然后显示该年龄对应的秒数。

#include <stdio.h>
int main()
{
    float i=3.156e7;
    float c;
    int b;
    printf("请输入年龄:\n");
    scanf("%d",&b);
    c=i*b;
    printf("您的年龄对应的秒数为:%e\n",c);
    printf("您的年龄对应的秒数也可以为:%f\n",c);
    return 0;
}

3.1个水分子的质量约为3.0*10^-23克。一夸脱水大约是950克。编写一个程序,提示用户输入水的夸脱数,并显示水分子的数量。

#include <stdio.h>
int main(void)
{
float mass_mol = 3.0e-23; 
float mass_qt = 950; 
float quarts;
float molecules;
printf("Enter the number of quarts of water: ");
scanf("%f", &quarts);
molecules = quarts * mass_qt / mass_mol;
printf("%f quarts of water contain %e molecules.\n", quarts, molecules); 
return 0;
}

—— —— —— —— —— —— —— —— —— —— —— 分割线
以下是今天随手练习的:

//platinum.c -- your weight in platinum
#include <stdio.h>
int main()
{
    float weight;
    float value;
    printf("Are you wroth you weight in platinum?\n");
    printf("Let's check it out.\n");
    printf("Please enter your weight in pounds : ");
    scanf("%f",&weight);
    value = 1700.0 * weight *14.5833;
    printf("Your weight in platinum is worth $%.2f.\n", value);
    printf("Your are easily worth that! If platinum prices drop,\n");
    return 0;
}

//以十进制、八进制、十六进制打印十进制数100
#include <stdio.h>
int main()
{
    int x = 100;
    printf("dec = %d; octal = %o; hex =%x\n", x, x, x);
    printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x);
    return 0;
    }

//显示字符的代码编号
#include <stdio.h>
int main()
{
    char ch;
    printf("Please ehter a character. \n");
    scanf("%c",&ch);
    printf("The code for %c is %d.\n", ch, ch);
    return 0;
}

//可移植整数类型名
#include <stdio.h>
#include <inttypes.h>
int main()
{
    int32_t me32;
    me32 = 45933945;
    printf("First, assum int32_t is int: ");
    printf("me32 = %d\n", me32);
    printf("Next, let's not make any assumptions.\n");
    printf("Instead, use a \" form inttypes.h: ");
    printf("me32 = %" PRId32 "\n", me32);
           return 0;
}

//以两种方式显示float类型的值
#include <stdio.h>
int main()
{
    float aboat = 32000.0;
    double abet = 2.14e9;
    long double dip = 5.32e-5;
    printf("%f can be written %e\n", aboat, aboat);
    printf("And it's %a in hexadecimal, powers of 2 notation\n", aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%Lf can be written %Le\n", dip, dip);
    return 0;
}

//用户年龄对应的秒数
#include <stdio.h>
int main()
{
    float i=3.156e7;
    float c;
    int b;
    printf("请输入年龄:\n");
    scanf("%d",&b);
    c=i*b;
    printf("您的年龄对应的秒数为:%e\n",c);
    printf("您的年龄对应的秒数也可以为:%f\n",c);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值