CPrimerPlus02

编写程序的步骤

1.定义程序目标
2. 设计程序
3. 编写代码
4. 编译
5. 运行程序
6. 测试和调试程序
7. 维护和修改程序



#include<stdio.h>
void main(void) {
    printf("Name is henry\n");
    printf("Address is shanghai\n");
    getchar();
    return 0;
}  

years:
#include<stdio.h>
int  main() {
    int ages, days;
    ages = 22;
    days = ages * 365;
    printf("My age is %d\nThat is %d days!\n ",ages,days);
    getchar();
    return 0;
}  

printf method:

#include<stdio.h>
void print_first();
void print_two();
int  main() {
    print_first();
    print_first();
    print_first();
    print_two();
    getchar();
    return 0;
}
void print_first(void) {
    printf("For he's a jolly good fellow!\n");
}
void print_two(void) {
    printf("Which nobody can deney!\n");
}  


#include<stdio.h>
int  main() {
    int toes=0,sum=0,square=0;
    toes = 10;
    sum = toes + toes;
    square = toes*toes;
    printf("value:%d\nSum:%d\nsquare:%d\n",toes,sum,square);
    getchar();
    return 0;
}  


#include<stdio.h>
void smile(void);
int  main() {
    smile();
    return 0;
}
void smile(void) {
    int n = 0; int j = 0;
    for(n=1;n<=3;n++)
    {
        for (j = 1; j <= n; j++) {
        printf("smile!");
        }
        printf("\n");
    }
    getchar();
    return 0;
}  


output;
smile!
smile!smile!
smile!smile!smile!

---
7.
#include<stdio.h>
void one_three();
void two();
void three();
int main(void) {
    printf("starting now:\n");
    one_three();
    two();
    three();
    printf("done!\n");
        getchar();
    return 0;
}
void one_three() {
    printf("one\n");
}
void two() {
    printf("two\n");
}
void three() {
    printf("three\n");
}
---

/*tall.c --身高显示*/
#include<stdio.h>
int main(void)
{
    char name[20];
    float tall = 0.0;
    printf("Please input your name and tall by cm\n");
    scanf("%s %f",name, &tall);
    printf("%s, you are tall %f m", name,tall/ 100);
    getchar();
    getchar();
    return 0;
}
---
/*printf.c --对齐显示*/
#include<stdio.h>
#include<string.h>
int main(void)
{
    char first_name[20];
    char last_name[20];
    int a = 0, b = 0;
    printf("Please input your first_name and last_name\n");
    scanf("%s %s", first_name, last_name);
    printf("%s %s\n", first_name, last_name);
    printf("%*d %*d\n", strlen(first_name), strlen(first_name),strlen(last_name), strlen(last_name)); //
    printf("%s %s\n", first_name, last_name);
    printf("%-*d %-*d\n", strlen(first_name), strlen(first_name),strlen(last_name), strlen(last_name));
    getchar();
    getchar();
    return 0;
}


Please input your first_name and last_name
henry tien
henry tien
    5    4
henry tien
5     4

6.
/*printf.c --打印double和float*/
#include<stdio.h>
#include<float.h>
int main(void)
{
    double a = 1.0 / 3.0;
    float b  = 1.0 / 3.0;
    printf("double a=1.0/3.0 float b=1.0/3.0\n%.4e %.4f\n",a,b);
    printf("%.12e %.12f\n",a,b);
    printf("%.16e %.16f\n",a,b);
    printf("%d\n",FLT_DIG);
    printf("%d\n",DBL_DIG);
    getchar();
    getchar();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值