91--100
第九十一題:求輸入的十個整數中正數的個數及其平均值。
#include <stdio.h>
#define SIZE 10void main()
{ int x[SIZE],i,n=0;
float sum=0;
printf(“Enter 10 integers:\n”); for(i=0;i<SIZE;i++)
{ printf("%d:",i+1); scanf("%d",&x[i]);
if(x[i]>0)
{
sum+=x[i];
n++; } } printf(“the counter is %d\n”,n); printf(“the average is %f\n”,sum/n);}
第九十二題:讀10個整數存入數組,找出其中最大值和最小值。
#include <stdio.h>
#define SIZE 10
void main()
{ int x[SIZE],i,max,min;
printf(“Enter 10 integers:\n”);
for(i=0;i<SIZE;i++)
{ printf("%d:",i+1);
scanf("%d",&x[i]); }
max=min=x[0];
for(i=1;i<SIZE;i++)
{ if(max<x[i])
max=x[i];
if(min>x[i]) min=x[i]; } printf(“Maximum value is %d\n”,max); printf(“Minimum value is %d\n”,min);}
第九十三題:輸入一行字符,統計其中的單詞個數,單詞間空格分開。
#include <stdio.h>
void main()
{ char string[81];
int i,num=0,word=0;
char c; gets(string)
; for(i=0;(c=string[i])!=’\0’;i++) if(c==’ ')
word=0;
else if(word==0)
{ word=1;
num++; } printf(“There are %d words in the line\n”,num);}
第九十四題:有一條長階梯:如果每步跨 2階,那么最后剩 1 階;如果每步跨 3 階,那么最后剩 2 階;如果每步跨 5 階,那么最后剩 4 階;如果每步跨 6 階,那么最后剩 5 階;只有當每步跨 7 階時,最后才正好走完, 一階不剩。請問這條階梯至少有多個階?
#include <stdio.h>
void main()
{ int n;
for(n=7;n<1000;n++) if(n%70&&n%65&&n%54&&n%43&&n%32&&n%21)
{ printf("%d\t",n);
break; } }
第九十五題:編寫程序求出 1000-2000 年之間的所有閏年,并統計個數。
#include"stdio.h”
void main(){
int year,num=0; for(year=1000;year<=2000;year++) if(year%40&&year%100!=0||year%4000) {
num++;
printf("%d “,year); } printf(”\ntotal is %d\n",num); }
第九十六題:計算10的階乘(10!)
#include"stdio.h"
void main()
{long int total=1;int n=1;while(n<=10){ total*=n; n++ ;} printf(“the result is %ld\n”,total);}
第九十七題:陽陽買蘋果,每個蘋果0.8元,陽陽第一天買兩個,第二天開始每天買前一天的兩倍,直到購買的蘋果個數為不超過100的最大值,編程求陽陽每天平均花多少錢?
#include"stdio.h"
void main()
{ int day=0,buy=2;
float sum=0.0,ave
; do {
sum+=0.8buy;
day++;
buy=2;
}while(buy<=100); ave=sum/day;
printf("%f\n",ave);}
第九十八題:編程求一個整數任意次方后的最后三位數,即求X^Y的最后三位數,X和Y的值由鍵盤輸入。
#include"stdio.h"
void main(){
int x, y, end=1;
int i; printf(“please input x and y:\n”); scanf("%d%d",&x,&y);
for (i=1;i<=y;i++) end=end*x%1000;
printf("%d",end);}
第九十九題:3對情侶參加婚禮,3個新。郎分別為a、b、c,三個新郎分別為 x、y、z。有人想知道究竟誰和誰結婚,于是就問新人中的三位,得到如下提示:a說 他將和X結婚;x說她的未婚夫是c;c說她將和z 結婚。這人時候知道他們都在開玩笑,說的全是假話,那么究竟誰和誰結婚吶。
#include <stdio.h>
vo
id main()
{ int a,b,c;
for (a=1; a<=3; a++)
for (b=1; b<=3; b++)
for (c=1; c<=3; c++) if (a!=1&&c!=1&&c!=3&&a!=b&&a!=c&&b!=c) { printf("%c will marry to a\n", ‘x’ + a - 1); printf("%c will marry to b\n", ‘x’ + b - 1); printf("%c will marry to c\n", ‘x’ + c - 1); }}
第一百題:根據輸入的三角形的三條邊判斷三角形的類型,并輸出它的面積和類型。提示:首先判斷所給的三條邊是否能組成三角形,若可以構成三角形,則判斷該三角形是什么類型,并求三角形面積 。
#include"stdio.h"
#include"math.h"
void main()
{ float a,b,c;
float s,area;
printf(“請輸入三角形的三條邊:\n”); scanf("%f%f%f",&a,&b,&c);
if (a+b>c&&b+c>a&&a+c>b)
{
s = (a+b+c)/2; area = sqrt(s*(s-a)(s-b)(s-c)); printf(“面積是:%f\n”,area);
if (ab && ac) printf(“等邊三角形\n”);
else if (ab || ac || b==c)
printf(“等腰三角形\n”); else if(aa + bb == cc || aa + cc == bb || bb + cc == a*a)
printf(“直角三角形\n”); else printf(“普通三角形\n”); } else printf(“不能構成三角形\n”);}
總結
- 上一篇: 拼数字
- 下一篇: yum没有被启用的仓库