77范文网 - 专业文章范例文档资料分享平台

C语言50道经典程序题(5)

来源:网络收集 时间:2019-03-29 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

getch(); }

============================================================== 【程序32】

题目:Press any key to change color, do you want to try it. Please hurry up! 1.程序分析: 2.程序源代码:

#include \#include \void main(void) {

int color;

for (color = 0; color < 8; color++) {

textbackground(color);/*设置文本的背景颜色*/ cprintf(\ cprintf(\ getch();/*输入字符看不见*/ } }

============================================================== 【程序33】

题目:学习gotoxy()与clrscr()函数 1.程序分析: 2.程序源代码:

#include \#include \void main(void) {

clrscr();/*清屏函数*/ textbackground(2); gotoxy(1, 5);/*定位函数*/

cprintf(\ textbackground(3); gotoxy(20, 10);

cprintf(\ getch(); }

==============================================================

【程序34】

题目:练习函数调用 1. 程序分析: 2.程序源代码:

#include \#include \void hello_world(void) {

printf(\}

void three_hellos(void) {

int counter;

for (counter = 1; counter <= 3; counter++) hello_world();/*调用此函数*/ }

void main(void) {

three_hellos();/*调用此函数*/ getch(); }

============================================================== 【程序35】

题目:文本颜色设置 1.程序分析: 2.程序源代码:

#include \#include \void main(void) {

int color;

for (color = 1; color < 16; color++) {

textcolor(color);/*设置文本颜色*/ cprintf(\ }

textcolor(128 + 15); cprintf(\ getch(); }

============================================================== 【程序36】

题目:求100之内的素数 1.程序分析: 2.程序源代码:

#include \#include \#define N 101 main() {

int i,j,line,a[N]; for(i=2;i

if(a!=0&&a[j]!=0) if(a[j]%a==0) a[j]=0; } printf(\

for(i=2,line=0;i

printf(\ line++; }

if(line==10) {

printf(\ line=0; } } getch(); }

============================================================== 【程序37】

题目:对10个数进行排序 1.程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换, 下次类推,即用第二个元素与后8个进行比较,并进行交换。 2.程序源代码:

#include \#include \#define N 10 main() {

int i,j,min,tem,a[N]; /*input data*/

printf(\ for(i=0;i

printf(\ scanf(\ }

printf(\ for(i=0;i

for(j=i+1;ja[j]) min=j; tem=a; a=a[min]; a[min]=tem; }

/*output data*/ printf(\ for(i=0;i

============================================================== 【程序38】

题目:求一个3*3矩阵对角线元素之和

1.程序分析:利用双重for循环控制输入二维数组,再将a累加后输出。 2.程序源代码:

#include \#include \

/* 如果使用的是TC系列编译器则可能需要添加下句 */ static void dummyfloat(float *x){ float y; dummyfloat(&y);} main() {

float a[3][3],sum=0; int i,j;

printf(\ for(i=0;i<3;i++) for(j=0;j<3;j++) scanf(\ for(i=0;i<3;i++) sum=sum+a;

printf(\ getch(); }

============================================================== 【程序39】

题目:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。 1. 程序分析:首先判断此数是否大于最后一个数,然后再考虑插入中间的数的情况,插入后

此元素之后的数,依次后移一个位置。 2.程序源代码:

#include \#include \main() {

int a[11]={1,4,6,9,13,16,19,28,40,100}; int temp1,temp2,number,end,i,j; printf(\ for(i=0;i<10;i++) printf(\ printf(\

printf(\ scanf(\ end=a[9]; if(number>end) a[10]=number; else {

for(i=0;i<10;i++) {

if(a>number)

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C语言50道经典程序题(5)在线全文阅读。

C语言50道经典程序题(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/555257.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: