C Primer Plus--第2章 C语言概述

2.12 编程练习

/*习题1:*/
#include<stdio.h>

int main(void) 
{
	printf("Anton Bruckner\n");
    printf("Anton\nBruckner\n");
    printf("Anton");
    printf("Bruckner\n");
	return 0;
}
Anton Bruckner
Anton
Bruckner
AntonBruckner
--------------------------------
Process exited after 0.2211 seconds with return value 0
请按任意键继续. . .
/*习题2:编写一个程序输出您的姓名及地址*/
#include<stdio.h>

int main(void)
{
	printf("Se7enLei\n");
	printf("China\n");
	
	return 0;
 } 
Se7enLei
China
--------------------------------
Process exited after 0.2216 seconds with return value 0
请按任意键继续. . .
/*习题3:编写一个程序,把您的年龄转换成天数并显示二者的值。*/
#include<stdio.h>

int main(void)
{
	int years,days;
	years=24;
	days=365*24;
	
	printf("My age is %d years old.\n",years);
	printf("Ddys is %d.\n",days);	
		
	return 0;
}
My age is 24 years old.
Ddys is 8760.
--------------------------------
Process exited after 0.1968 seconds with return value 0
请按任意键继续. . .

/*习题4:*/
#include<stdio.h>

void a(void);
void b(void);

int main(void)
{
	a();
	a();
	a();
	b();

	return 0;
}
void a(void)
{
	printf("For he's a jolly good fellow!\n");
}
void b(void)
{
	printf("Which nobody can deny!\n");
}
For he's a jolly good fellow!
For he's a jolly good fellow!
For he's a jolly good fellow!
Which nobody can deny!
--------------------------------
Process exited after 0.02982 seconds with return value 0
请按任意键继续. . .
/*习题5:编写一个程序,创建名为toes的整数变量。让程序把toes设置为10。再让程序计算两个toes的和以及toes的平方。程序应该输出所有的3个值,并分别标示它们。*/
#include <stdio.h>

int main(void)
{
	int toes,toes_add,toes_square;
	toes=10;
	toes_add=toes+toes;
	toes_square=toes*toes;
	
	printf("toes=%d.\n",toes);
	printf("toes_add=%d.\n",toes_add);
	printf("toes_square=%d.\n",toes_square);
	
	return 0;
}
toes=10.
toes_add=20.
toes_square=100.
--------------------------------
Process exited after 0.182 seconds with return value 0
请按任意键继续. . .
/*习题6:*/
#include <stdio.h>

void smile(void);
int main(void)
{

	smile();
	smile();
	smile();
	printf("\n");
	
    smile();
	smile();
	printf("\n");
    
	smile();
	printf("\n");
	
	return 0;
}

void smile(void)
{
	printf("smile!");
}
smile!smile!smile!
smile!smile!
smile!
--------------------------------
Process exited after 0.3496 seconds with return value 0
请按任意键继续. . .
/*习题7:*/
#include <stdio.h>

void one_three(void);
void two(void);

int main(void)
{
	printf("sarting now:\n");
	one_three();
    printf("done!\n");
    
	return 0;
}

void one_three(void)

{
	printf("one\n");
	two();
	printf("three\n");
} 

void two(void)
{
	printf("two\n");
} 
sarting now:
one
two
three
done!
--------------------------------
Process exited after 0.1988 seconds with return value 0
请按任意键继续. . .
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值