C语言典范编程

目:给一个不多于5位的正整数,要求:一、求它是 几位数,二、逆序打印出列位数字.
1,程序解析:学会分化出每一名数,似下讲明:(这个地方是 一种简单的算法,师专数002班*鑫供应)
2,程序源代码:
main( )
{
long a,b,c,d,e,x;
scanf(“%ld”,&x);
a=x10000;分化出万位
b=x%100001000;分化出千位
c=x%1000100;分化出百位
d=x%10010;分化出十位
e=x%10;分化出个位
if (a!=0) printf(“there are 5,%ld %ld %ld %ld %ld\n”,e,d,c,b,a);
else if (b!=0) printf(“there are 4,%ld %ld %ld %ld\n”,e,d,c,b);
  else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c);
    else if (d!=0) printf(“there are 2,%ld %ld\n”,e,d);
      else if (e!=0) printf(" there are 1,%ld\n",e);
}

【程序30】
题目:一个5位数,判断它是 不是 回文数.即12321是 回文数,个位与万位同样,十位与千位同样.   
1,程序解析:同29例
2,程序源代码:
main( )
{
long ge,shi,qian,wan,x;
scanf(“%ld”,&x);
wan=x10000;
qian=x%100001000;
shi=x%10010;
ge=x%10;
if (gewan&&shiqian)个位等于万位同时且十位等于千位
 printf(“this number is a huiwen\n”);
else
 printf(“this number is not a huiwen\n”);
}
【程序31】
题目:请输入星期几的第一个字母来判断一下是 星期几,介入第一个字母同样,那么接着
   判断第二个字母.
1,程序解析:用状况语句对比好,介入第一个字母同样,那么判断用状况语句或if语句判断第二个字母.
2,程序源代码:
#include <stdio.h>
void main()
{
char letter;
printf(“please input the first letter of someday\n”);
while ((letter=gainch())!=‘Y’)当所按字母为Y时才终了
{ switch (letter)
{case ‘S’:printf(“please input second letter\n”);
     if((letter=gainch())‘a’)
      printf(“saturday\n”);
     else if ((letter=gainch())
‘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=gainch())‘u’)
      printf(“tuesday\n”);
     else if ((letter=gainch())
‘h’)
         printf(“thursday\n”);
       else printf(“data error\n”);
     break;
case ‘W’:printf(“wednesday\n”);break;
default:printf(“data error\n”);
  }
 }
}

【程序32】
题目:Press any key to change color,do you desire to try it.Please hurry up!
1,程序解析:            
2,程序源代码:
#include <conio.h>
void main(void)
{
int color;
for (color = 0;color < 8;color++)
 {
 textbackground(color);设置文本的背景颜色
 cprintf(“This is color %d\r\n”,color);
 cprintf(“Press any key to continue\r\n”);
 gainch();输入字符看不见
 }
}

【程序33】
题目:进修gotoxy()与clrscr()函数   
1,程序解析:
2,程序源代码:
#include <conio.h>
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”);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cdbycd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值