【程序31】
题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续
   判断第二个字母。
1.程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。
2.程序源代码:
#include <stdio.h>
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");
  }
 }
}
==============================================================
【程序32】
题目:Press any key to change color, do you want 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");
 getch();/*输入字符看不见*/
 }
}
==============================================================
【程序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");
}
==============================================================
【程序34】
题目:练习函数调用
1. 程序分析:
2.程序源代码:
#include <stdio.h>
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();/*调用此函数*/
}
==============================================================
【程序35】
题目:文本颜色设置
1.程序分析:
2.程序源代码:
#include <conio.h>
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");
}
==============================================================
【程序36】
题目:求100之内的素数   
1.程序分析:
2.程序源代码:
#include <stdio.h>
#include "math.h"
#define N 101
main()
{
int i,j,line,a[N];
for(i=2;i<N;i++) a[i]=i;
for(i=2;i<sqrt(N);i++)
 for(j=i+1;j<N;j++)
 {
  if(a[i]!=0&&a[j]!=0)
  if(a[j]%a[i]==0)
  a[j]=0;}
printf("\n");
for(i=2,line=0;i<N;i++)
{
 if(a[i]!=0)
 {printf("%5d",a[i]);
 line++;}
 if(line==10)
 {printf("\n");
line=0;}
}
}
==============================================================
【程序37】
题目:对10个数进行排序
1.程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换,
      下次类推,即用第二个元素与后8个进行比较,并进行交换。       
2.程序源代码:
#define N 10
main()
{int i,j,min,tem,a[N];
/*input data*/
printf("please input ten num:\n");
for(i=0;i<N;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);}
printf("\n");
for(i=0;i<N;i++)
printf("%5d",a[i]);
printf("\n");
/*sort ten num*/
for(i=0;i<N-1;i++)
{min=i;
for(j=i+1;j<N;j++)
if(a[min]>a[j]) min=j;
tem=a[i];
a[i]=a[min];
a[min]=tem;
}
/*output data*/
printf("After sorted \n");
for(i=0;i<N;i++)
printf("%5d",a[i]);
}
==============================================================
【程序38】
题目:求一个3*3矩阵对角线元素之和
1.程序分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出。
2.程序源代码:
main()
{
float a[3][3],sum=0;
int i,j;
printf("please input rectangle element:\n");
for(i=0;i<3;i++)
 for(j=0;j<3;j++)
 scanf("%f",&a[i][j]);
for(i=0;i<3;i++)
 sum=sum+a[i][i];
printf("duijiaoxian he is %6.2f",sum);
}
==============================================================
【程序39】
题目:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。
1. 程序分析:首先判断此数是否大于最后一个数,然后再考虑插入中间的数的情况,插入后
     此元素之后的数,依次后移一个位置。
2.程序源代码:
main()
{
int a[11]={1,4,6,9,13,16,19,28,40,100};
int temp1,temp2,number,end,i,j;
printf("original array is:\n");
for(i=0;i<10;i++)
 printf("%5d",a[i]);
printf("\n");
printf("insert a new number:");
scanf("%d",&number);
end=a[9];
if(number>end)
 a[10]=number;
else
 {for(i=0;i<10;i++)
  { if(a[i]>number)
   {temp1=a[i];
    a[i]=number;
   for(j=i+1;j<11;j++)
   {temp2=a[j];
    a[j]=temp1;
    temp1=temp2;
   }
   break;
   }
  }
}
for(i=0;i<11;i++)
 printf("%6d",a[i]);
}
==============================================================
【程序40】
题目:将一个数组逆序输出。
1.程序分析:用第一个与最后一个交换。
2.程序源代码:
#define N 5
main()
{ int a[N]={9,6,5,4,1},i,temp;
 printf("\n original array:\n");
 for(i=0;i<N;i++)
 printf("%4d",a[i]);
 for(i=0;i<N/2;i++)
 {temp=a[i];
  a[i]=a[N-i-1];
  a[N-i-1]=temp;
 }
printf("\n sorted array:\n");
for(i=0;i<N;i++)
 printf("%4d",a[i]);
}

经典c程序100例==31--40的更多相关文章

  1. 经典c程序100例==91--100

    [程序91] 题目:时间函数举例1 1.程序分析: 2.程序源代码: #include "stdio.h" #include "time.h" void mai ...

  2. 经典c程序100例 1-10

    ==1--10 [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不 ...

  3. 经典c程序100例==21--30

    [程序21] 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个.以后每天早上都吃了前一天剩下 的一半零一个.到第10天早 ...

  4. 经典c程序100例==41--50

    [程序41] 题目:学习static定义静态变量的用法 1.程序分析: 2.程序源代码: #include "stdio.h" varfunc() { int var=0; sta ...

  5. 经典c程序100例==51--60

    [程序51] 题目:学习使用按位与 & . 1.程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1 2.程序源代码: #include " ...

  6. 经典c程序100例==11--20

    [程序11] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月 后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1 ...

  7. 经典c程序100例==71--80

    [程序71] 题目:编写input()和output()函数输入,输出5个学生的数据记录. 1.程序分析: 2.程序源代码: #define N 5 struct student { char num ...

  8. 经典c程序100例==81--90

    [程序81] 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数.求??代表的两位数,及809*??后的结果. 1.程序分析: 2.程 ...

  9. 经典c程序100例==61--70

    [程序61] 题目:打印出杨辉三角形(要求打印出10行如下图) 1.程序分析: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 2.程序源代码: main() ...

随机推荐

  1. git 查看本地分支和切换本地分支的命令

    查看本地分支,和当前所在的分支 git branch -vv git checkout developer 切换到developer分支

  2. http_parser

    最近读了 http_parser 的源码,记录下.    有意思的地方: 1)  协议解析可以不完全解析完,但是当前 parser 会记录解析状态,这样可以继续解析 2)  协议解析首要还是要了解协议 ...

  3. Linux Centos7 安装Docker-CE

    先确保yum 是最新版本 执行: sudo yum update 添加docker源地址 sudo yum-config-manager --add-repo https://download.doc ...

  4. 佛山6397.7539(薇)xiaojie:佛山哪里有xiaomei

    佛山哪里有小姐服务大保健[微信:6397.7539倩儿小妹[佛山叫小姐服务√o服务微信:6397.7539倩儿小妹[佛山叫小姐服务][十微信:6397.7539倩儿小妹][佛山叫小姐包夜服务][十微信 ...

  5. 【图论】HDU 5961 传递

    题目内容 题目链接 我们称一个有向图G是传递的当且仅当对任意三个不同的顶点a,若G中有 一条边从a到b且有一条边从b到c ,则G中同样有一条边从a到c. 我们称图G是一个竞赛图,当且仅当它是一个有向图 ...

  6. centos8安装RabbitMQ

    一.安装erlang # 添加仓库 curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh ...

  7. centos8平台使用xfs文件系统

    一,xfs文件系统的特点 XFS是一种高性能的日志文件系统, 它是由SGI公司设计的,被称为业界最先进的.最具可升级性的文件系统技术. 最初是从unix(irix)移植到linux系统上的. 从cen ...

  8. selenium 设置代理ip

    from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument("--prox ...

  9. T-sql语句,group by 加 order by的使用方法

    select AuHousesID,sum(Turnover) from Auction group by AuHousesID order by sum(Turnover) desc

  10. Linux-京西百花山

    百花山有三个收票的入口,分别在门头沟(G109).房山(G108)和河北 108有两个方向上百花山,史家营和四马台.只有史家营方向能开车到山顶. 四马台那边,不住,要坐景区车才行 尽头是1900多米的 ...