欢迎来到天天文库
浏览记录
ID:55469800
大小:426.00 KB
页数:109页
时间:2020-05-14
《C语言基本算法程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、(╯_╰)母鸡荣誉作品以下一百例C语言基本程序算法出自C语言基本算法程序一百例.pdf的word形式,并经过本人亲自在vc6.0上编写运行完美!!!第一章最简单的问题与算法1.绘制余弦曲线源程序:#include#includevoidmain(){doubley;intx,m;for(y=1;y>-1;y-=0.1)//y为列方向{m=acos(y)*10;//y对应的弧度mfor(x=1;x2、tf("");printf("*");}}运行结果:******************************************Pressanykeytocontinue2..绘制余弦曲线和直线源代码:#include#includevoidmain(){doubley;intx,m,n,yy;for(yy=0;yy<=20;yy++){y=0.1*yy;//y:屏幕行方向坐标m=acos(1-y)*10;//m:cos(x)曲线上y点对应的屏幕列坐标n=45*(y-1)+31;f3、or(x=0;x<=62;x++)if(x==m&&x==n)printf("+");elseif(x==n)printf("+");elseif(x==m4、5、x==62-m)printf("*");elseprintf("");printf("");}}运行结果:******+**+**+***+**+**+**+**+**+**+**+**+**+**+**+*****3.绘制圆源代码:#include#includevoidmain(){doubley;intx,m;for(y=106、;y>=-10;y--)//圆的半径为10{m=2.5*sqrt(100-y*y);//行y对应的列坐标m。2.5是屏幕纵横比调节系数,//因为屏幕的行距大于列距,不进行调节的话就显示为椭圆for(x=1;x<30-m;x++)printf("");printf("*");for(;x<30+m;x++)printf("");printf("*");}}运行结果:******************************************Pressanykeytocontinue4.歌星大奖赛源代码:#includ7、e#includevoidmain(){intinteger,i,max,min,sum;max=-32768;min=32767;//-32768~+32767为C语言的整型数的最值sum=0;for(i=1;i<=10;i++){printf("inputnumber%d=",i);scanf("%d",&integer);sum+=integer;if(integer>max)max=integer;if(integer8、maxscore:%dCanceleminscore:%d",max,min);printf("Averagescore:%d",(sum-max-min)/8);}运行结果:inputnumber1=90inputnumber2=91inputnumber3=93inputnumber4=90inputnumber5=94inputnumber6=97inputnumber7=99inputnumber8=95inputnumber9=92inputnumber10=97Canceledmaxscore:99Ca9、nceleminscore:90Averagescore:93Pressanykeytocontinue5.求最大约数源代码:#include#includevoidmain(){longi;intj;printf("pleseinputnumber:");scanf("%ld",&i);for(j=999;j>=100;j--)if(i%j==0){printf("Themaxfactorwith3digitsin%ldis:%d.",i,j);break;}}运行结果:pleseinp10、utnumber:Themaxfactorwith3digitsinis:777.Pressanykeytocontinue6.高次方数的尾数源代码:#include#includevoidmain(){inti,x,y,last=1;pri
2、tf("");printf("*");}}运行结果:******************************************Pressanykeytocontinue2..绘制余弦曲线和直线源代码:#include#includevoidmain(){doubley;intx,m,n,yy;for(yy=0;yy<=20;yy++){y=0.1*yy;//y:屏幕行方向坐标m=acos(1-y)*10;//m:cos(x)曲线上y点对应的屏幕列坐标n=45*(y-1)+31;f
3、or(x=0;x<=62;x++)if(x==m&&x==n)printf("+");elseif(x==n)printf("+");elseif(x==m
4、
5、x==62-m)printf("*");elseprintf("");printf("");}}运行结果:******+**+**+***+**+**+**+**+**+**+**+**+**+**+**+*****3.绘制圆源代码:#include#includevoidmain(){doubley;intx,m;for(y=10
6、;y>=-10;y--)//圆的半径为10{m=2.5*sqrt(100-y*y);//行y对应的列坐标m。2.5是屏幕纵横比调节系数,//因为屏幕的行距大于列距,不进行调节的话就显示为椭圆for(x=1;x<30-m;x++)printf("");printf("*");for(;x<30+m;x++)printf("");printf("*");}}运行结果:******************************************Pressanykeytocontinue4.歌星大奖赛源代码:#includ
7、e#includevoidmain(){intinteger,i,max,min,sum;max=-32768;min=32767;//-32768~+32767为C语言的整型数的最值sum=0;for(i=1;i<=10;i++){printf("inputnumber%d=",i);scanf("%d",&integer);sum+=integer;if(integer>max)max=integer;if(integer8、maxscore:%dCanceleminscore:%d",max,min);printf("Averagescore:%d",(sum-max-min)/8);}运行结果:inputnumber1=90inputnumber2=91inputnumber3=93inputnumber4=90inputnumber5=94inputnumber6=97inputnumber7=99inputnumber8=95inputnumber9=92inputnumber10=97Canceledmaxscore:99Ca9、nceleminscore:90Averagescore:93Pressanykeytocontinue5.求最大约数源代码:#include#includevoidmain(){longi;intj;printf("pleseinputnumber:");scanf("%ld",&i);for(j=999;j>=100;j--)if(i%j==0){printf("Themaxfactorwith3digitsin%ldis:%d.",i,j);break;}}运行结果:pleseinp10、utnumber:Themaxfactorwith3digitsinis:777.Pressanykeytocontinue6.高次方数的尾数源代码:#include#includevoidmain(){inti,x,y,last=1;pri
8、maxscore:%dCanceleminscore:%d",max,min);printf("Averagescore:%d",(sum-max-min)/8);}运行结果:inputnumber1=90inputnumber2=91inputnumber3=93inputnumber4=90inputnumber5=94inputnumber6=97inputnumber7=99inputnumber8=95inputnumber9=92inputnumber10=97Canceledmaxscore:99Ca
9、nceleminscore:90Averagescore:93Pressanykeytocontinue5.求最大约数源代码:#include#includevoidmain(){longi;intj;printf("pleseinputnumber:");scanf("%ld",&i);for(j=999;j>=100;j--)if(i%j==0){printf("Themaxfactorwith3digitsin%ldis:%d.",i,j);break;}}运行结果:pleseinp
10、utnumber:Themaxfactorwith3digitsinis:777.Pressanykeytocontinue6.高次方数的尾数源代码:#include#includevoidmain(){inti,x,y,last=1;pri
此文档下载收益归作者所有