国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

經典c程序100例==31--40

2019-11-17 05:46:55
字體:
來源:轉載
供稿:網友
【程序31】
題目:請輸入星期幾的第一個字母來判定一下是星期幾,假如第一個字母一樣,則繼續
   判定第二個字母。
1.程序分析:用情況語句比較好,假如第一個字母一樣,則判定用情況語句或if語句判定第二個字母。
2.程序源代碼:
#include <stdio.h>
void main()
{
char letter;
while ((letter=getch())!='Y')/*當所按字母為Y時才結束*/
{ switch (letter)
{case 'S':printf("please input second letter ");
     if((letter=getch())=='a')
      printf("saturday ");
     else if ((letter=getch())=='u')
         printf("sunday ");
       else printf("data error ");
     break;
case 'F':printf("friday ");break;
case 'M':printf("monday ");break;
case 'T':printf("please input second letter ");
     if((letter=getch())=='u')
      printf("tuesday ");
     else if ((letter=getch())=='h')
         printf("thursday ");
       else printf("data error ");
     break;
case 'W':printf("wednesday ");break;
default: printf("data error ");
  }
 }
}
==============================================================
【程序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 ", color);
 cprintf("Press any key to continue ");
 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 ");
textbackground(3);
gotoxy(20, 10);
cprintf("Output at row 10 column 20 ");
}
==============================================================
【程序34】
題目:練習函數調用
1. 程序分析:
2.程序源代碼:
#include <stdio.h>
void hello_world(void)
{
printf("Hello, world! ");
}
void three_hellos(void)
{
int counter;
for (counter = 1; counter <= 3; counter++)
hello_world();/*調用此函數*/
}
void main(void)

==============================================================
 【程序35】
題目:文本顏色設置
1.程序分析:
2.程序源代碼:
#include <conio.h>
void main(void)
{
int color;
for (color = 1; color < 16; color++)
 {
 textcolor(color);/*設置文本顏色*/
 cprintf("This is color %d ", color);
 }
textcolor(128 + 15);
cprintf("This is blinking ");
}
==============================================================
【程序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++)
 
printf(" ");
for(i=2,line=0;i<N;i++)

 if(line==10)
 {printf(" ");
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: ");
for(i=0;i<N;i++)

printf(" ");
for(i=0;i<N;i++)
printf("%5d",a[i]);
printf(" ");
/*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 ");
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: ");
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]=;
int temp1,temp2,number,end,i,j;
printf("original array is: ");
for(i=0;i<10;i++)
 printf("%5d",a[i]);
printf(" ");
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)
   
   break;
   }
  }
}
for(i=0;i<11;i++)
 printf("%6d",a[i]);
}
==============================================================
【程序40】
題目:將一個數組逆序輸出。
1.程序分析:用第一個與最后一個交換。
2.程序源代碼:
#define N 5
main()
{ int a[N]=,i,temp;
 printf(" original array: ");
 for(i=0;i<N;i++)
 printf("%4d",a[i]);
 for(i=0;i<N/2;i++)
 
printf(" sorted array: ");
for(i=0;i<N;i++)
 printf("%4d",a[i]);
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁乡县| 禄劝| 苍溪县| 克什克腾旗| 自贡市| 杭锦后旗| 西安市| 开江县| 柯坪县| 察隅县| 民和| 徐水县| 西宁市| 武功县| 棋牌| 贞丰县| 商水县| 肥东县| 宽甸| 台山市| 朝阳市| 古交市| 武穴市| 易门县| 清涧县| 西安市| 富源县| 广州市| 内乡县| 洛扎县| 鹿邑县| 娄烦县| 万宁市| 厦门市| 乐都县| 东光县| 丹江口市| 时尚| 余干县| 贞丰县| 梓潼县|