新建做業20191011120939

1.編寫一個程序,調用一次printf()函數,把你的姓名分別打印在一行。再調用一次printf()函數,把你的姓名分別打印在兩行。而後,再調用兩次printf()函數,把你的姓名打印在一行。

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

2.編寫一個程序,打印你的姓名和地址。

#include<stdio.h>
int main(void)
{
	printf("朱妍\n");
	printf("浙江樹人大學\n");
	return 0;
}

3.編寫一個程序把你的年齡轉換整天數,並顯示這兩個值。這裏不用考慮閏年的問題。

#include<stdio.h>
int main(void)
{
	int ageYear;
	int ageDays;
	int totalDays;
	ageYear=18;
	ageDays=365;
	totalDays=ageYear*ageDays;
	printf("totalDays=%d",totalDays);
	return 0;
}

4.編寫一個程序,生成如下輸出:

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! 除了main()函數之外,該程序還要調用兩個自定義函數:一個名爲jolly(),用於打印前三條消息,調用一次打印一條;另外一個函數名爲deny(),打印最後一條消息。函數

#include<stdio.h>
void jolly();
void deny();
int main(void)
{
	jolly();
	jolly();
	jolly();
	deny(); 
	return 0;
}
void jolly()
{
	printf("For he's a jolly good fellow!\n");
}

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

5.編寫一個程序,生成如下輸出:

Brazil,Russia,India,China India,China Brazil,Russia 除了main()之外,該程序還要調用兩個自定義函數:一個名爲br(),調用一次打印一次「Brazil,Russia」;另外一個名爲ic(),調用一次打印一次「India,China"。其餘內容在main()函數中完成。code

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

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

void ic()
{
	printf("Lndia,China");
}

6.編寫一個程序,建立一個整型變量toes,並將toes設置爲10.程序中還要計算toes的兩倍和toes的平方。該程序應打印3個值,並分別描述以示區分。

#include<stdio.h>
int main(void)
{
	int toes=10;
	int dbtoes,pftoes;
	dbtoes=toes*2;
	pftoes=toes*toes;
	printf("%d\n",toes);
	printf("%d\n",dbtoes);
	return 0;	
}

7.許多研究代表,微笑益處多多。編寫一個程序,生成如下格式的輸出:Smile!Smile!Smile!

Smile!Smile! Smile! 該程序要定義一個函數,該函數被調用一次打印一次「Smile!",根據程序的須要使用該函數。three

#include<stdio.h>
void wx();
void hh();
int main(void)

{
	wx();
	wx();
	wx();
	hh();
	wx();
	wx();
	hh();
	wx();
	hh();
	return 0;
}

void wx()
{
	printf("Smile!");
}

void hh()
{
	printf("\n");
}

8.在C語言中,函數能夠調用另外一個函數。編寫一個程序,調用一個名爲one_three()的函數。該函數在一行打印單詞「one」,再調用第二個函數two(),而後在另外一行打印單詞「three」。two()函數在一行顯示單詞「two"。main()函數在調用one-three()函數前要打印短語「staring now」,並在調用完107畢後顯示短語「done!」。

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

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

void two()
{
	printf("two\n");
}
相關文章
相關標籤/搜索