设为首页 加入收藏

TOP

c-大量经典的c算法---ShinePans(六)
2015-01-22 21:34:54 来源: 作者: 【 】 浏览:220
Tags:大量 经典 算法 ---ShinePans
**
******
********
******
***
*
___________________________________________________________________


程序分析:先把图形分成两部分来看待,前四行一个规律,后三行一个规律,利
用双重for循环,第一层控制行,第二层控制列。
___________________________________________________________________


程序源代码:
main()
{
int i,j,k;
for(i=0;i<=3;i++)
{
for(j=0;j<=2-i;j++)
printf(" ");
for(k=0;k<=2*i;k++)
printf("*");
printf("\n");
}
for(i=0;i<=2;i++)
{
for(j=0;j<=i;j++)
printf(" ");
for(k=0;k<=4-2*i;k++)
printf("*");
printf("\n");
}
}


题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,
十位与千位相同。
___________________________________________________________________


程序分析:同29例
___________________________________________________________________


程序源代码:
main( )
{
long ge,shi,qian,wan,x;
scanf("%ld",&x);
wan=x/10000;
qian=x%10000/1000;
shi=x%100/10;
ge=x%10;
if (ge==wan&&shi==qian)/*个位等于万位并且十位等于千位*/
printf("this number is a huiwen\n");
else
printf("this number is not a huiwen\n");
}




题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,
则继续判断第二个字母。
___________________________________________________________________


程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语
句判断第二个字母。
___________________________________________________________________


程序源代码:
#include
void main()
{
char letter;
printf("please input the first letter of someday\n");
while ((letter=getch())!='Y') /*当所按字母为Y时才结束*/
{ switch (letter)
{case 'S':printf("please input second letter\n");
if((letter=getch())=='a')
printf("saturday\n");
else if ((letter=getch())=='u')
printf("sunday\n");
else printf("data error\n");
break;
case 'F':printf("friday\n");break;
case 'M':printf("monday\n");break;
case 'T':printf("please input second letter\n");
if((letter=getch())=='u')
printf("tuesday\n");
else if ((letter=getch())=='h')
printf("thursday\n");
else printf("data error\n");
break;
case 'W':printf("wednesday\n");break;
default: printf("data error\n");
}
}
}


题目:Press any key to change color, do you want to try it. Please
hurry up!
___________________________________________________________________


程序源代码:
#include
void main(void)
{
int color;
for (color = 0; color < 8; color++)
{
textbackground(color); /*设置文本的背景颜色*/
cprintf("This is color %d\r\n", color);
cprintf("ress any key to continue\r\n");
getch(); /*输入字符看不见*/
}
}


题目:学习gotoxy()与clrscr()函数
___________________________________________________________________


程序源代码:
#include
void main(void)
{
clrscr(); /*清屏函数*/
textbackground(2);
gotoxy(1, 5); /*定位函数*/
cprintf("Output at row 5 column 1\n");
textbackground(3);
gotoxy(20, 10);
cprintf("Output at row 10 column 20\n");
}




题目:练习函数调用
___________________________________________________________________


程序源代码:
#include
void hello_world(void)
{
printf("Hello, world!\n");
}
void three_hellos(void)
{
int counter;
for (counter = 1; counter <= 3; counter++)
hello_world();/*调用此函数*/
}
void main(void)
{
three_hellos();/*调用此函数*/
}




题目:文本颜色设置
___________________________________________________________________


程序源代码:
#include
void main(void)
{
int color;
for (color = 1; color < 16; color++)
{
textcolor(color);/*设置文本颜色*/
cprintf("This is color %d\r\n", color);
}
textcolor(128 + 15);
cprintf("This is blinking\r\n");
}


题目:求100之内的素数
___________________________________________________________________


程序源代码:
#include
#include "math
首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇浅谈c语言typedef 与结构体指针(.. 下一篇Objective-c学习笔记―― Ubuntu ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: