C 语言描述 -编程练习

本文提供了一系列C语言编程练习,包括基本的输出操作、简单的数学计算、函数调用等,旨在帮助初学者掌握C语言的基本语法和编程技巧。

C 语言描述 -编程练习

/*
 ============================================================================
 Name        : practice.c
 Author      : liu
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */
//#include<> 加载另一个文件
#include <stdio.h>

//String.h  支持字符串操作的库函数
#include <String.h>

//void 方法名();  声明方法

/*
 *第一行打印你的姓和名字
 *第二行打印你的姓
 *第三行打印你的名字
 *第四行打印你的名字
 */
void one();
void two(char name[], char address[]);

/*
 *把年龄换成天数计算,不考虑闰年问题
 */
void three(int age);

/*
 *该函数调用两个自定义函数,一个名为jolly(),用于打印前三条消息
 *另一个函数名为deny(),打印最后一条信息
 */
void four();
void jolly();
void deny();

/*
 *调用两个自定义函数,一个名为br();调用一次打印"Brazil,Russia";
 *另一个名为ic(),调用一次打印"India,china",其他内容在five()函数中显示
 */
void five();
void br();
void ic();

/*创建一个整形变量toes,并将toes设置为10,需要计算toes的两倍和toes的平方
 */
void six();

/*
 *定义一个函数,函数被调用一次打印一次"Smile",调用几次函数就打印几次
 */
void seven();void smile(int time);

/*
 *调用一个名为one_three()的函数,函数在一行打印单词"one",在调用第二个函数two(),然后再另一行打印three,eight()
 *函数在调用one_three()函数前要打印短语Starting now,并在调用完毕后显示短语done
 */
void eight(); void one_three(char time[]);

/*
 * main  C程序入口
 * puts(str);将str输出到标准输出设备,并换行
 */
int main(void) {
	//puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */

	//调用one方法,无实际参数
	//one();

	//("liu tom","American");

	//three(23);

	//four();

	//five();

	//six();

	//seven();

	eight();

	return 0;
}

/*
 *	printf(); 将内容输出到标准输出设备  f的意思是允许格式化
 *	\n 允许换行
 *	%s 定义在字符串该位置打印字符串变量
 */
void one() {
	printf("liu tom\n");
	printf("%s\n%s\n", "liu", "tom");
	printf("%s", "liu tom");

	return;
}

void two(char name[], char address[]) {
	printf("我的名字是:%s\n", name);
	printf("我的地址是:%s\n", address);

	return;
}

void three(int age) {
	printf("天数是:%d", age * 360);
}
;

void four() {
	jolly();
	deny();
}
;
void jolly() {
	for (int i = 0; i < 2; i++) {
		printf("For he’s a jolly good fellow!\n");
	};

	return;
}
;

void deny() {
	printf("Which nobody can dency!\n");

	return;
}
;

void five() {
	br();
	ic();
	printf("India,China,\nBrazil,Russia");

	return;
}
;

void br() {
	printf("Brazil,Russia,");

	return;
}
;

void ic() {
	printf("India,China\n");

	return;
}
;

void six() {

	int toes;
	toes = 10;
	printf("%d的两倍为%d,平方为:%d", toes, toes * 2, toes * toes);

	return;
}

void seven() {
	int times = 20;
	for (int i = 1; i <= times; i++) {
		smile(i);
	};

	return;
}

void smile(int time) {
	for (int i = 1; i < time; i++) {
		printf("Smile!");
	};
	printf("\n");

	return;
};

void eight(){
	printf("starting now:\n");
	for(int i=1;i<=3;i++){
		switch(i){
		case 1:
			one_three("one");
			break;
		 case 2:
			 one_three("two");
			 break;
		 case 3:
			 one_three("three");
			 break;
		};
	};
	printf("done!");

	return;};
void one_three(char time[]){
     printf("%s\n",time);

	return;
};

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值