C语言基础学习1

 输入一个ASCII码值,打印输出的字符

#include<stdio.h>
int main(void)
{
    int ch;
    scanf("%d",&ch);
    printf("%d is %c\n",ch,ch);
    return 0;
}

输出"Great!" 

 #include<stdio.h>
int main(void)
{
    printf("\"Great!\"\n");
    return 0;
}

输出格式控制 

#include<stdio.h>
int main(void)
{
    float i;
    scanf("%f",&i);
    printf("输出:\n%.6f\n%e\n",i,i);
    return 0;
}

64.25
输出:
64.250000
6.425000e+001 

 #include<stdio.h>
int main(void)
{
    int age;
    double time;
    time=3.156e7;
    scanf("%d",&age);
    printf("年龄%d对应的秒数为:%e\n",age,age*time);
    return 0;
}

18
年龄18对应的秒数为:5.680800e+008

#include<stdio.h>
int main(void)
{
    int member,k;
    double f;
    k=950;
    f=3e-23;
    scanf("%d",&member);
    printf("%d夸脱水分子的质量为:%d 数量为:%e\n",member,member*k,member*k/f);
    return 0;
}

#include<stdio.h>
int main(void)
{
    float k;
    printf("输入身高(英尺):");
    scanf("%f",&k);
    printf("身高为:%.2f厘米\n",k*2.45);
    return 0;
}

输入身高(英尺):70
身高为:171.50厘米

#include<stdio.h>
#include<string.h>//提供strlen()函数的原型
#define DENSITY 62.4//定义字符常量
int main(void)
{
    float weight,volume;
    int size,letters;
    char name[40];
    printf("What's your first name?\n");
    scanf("%s",name);//name前面无&
    printf("%s,what's your weight in pounds?\n",name);
    scanf("%f",&weight);//weight前面有&
    size=sizeof(name);
    letters=strlen(name);
    volume=weight/DENSITY;
    printf("%s,your volume is %2.2f cubic feet.\n",name,volume);
    printf("your first name has %d letters,",letters);
    printf("and we have %d bytes to store it.\n",size);
    return 0;
}

What's your first name?
ahhhhh
ahhhhh,what's your weight in pounds?
111
ahhhhh,your volume is 1.78 cubic feet.
your first name has 6 letters,and we have 40 bytes to store it.

#include<stdio.h>
#define P "I love you!"
int main(void)
{
    char name[40];
    printf("What's your name?\n");
    scanf("%s",name);//name前面无&
    printf("%s,%s\n",name,P);
    return 0;
}

What's your name?
baby
baby,I love you!

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值