当前位置:首页 » 《随便一记》 » 正文

一份作业(霉霉镇楼)_coyafky的博客

19 人参与  2022年03月30日 13:25  分类 : 《随便一记》  评论

点击全文阅读


 

#include <stdio.h>
 void  one_houzi_eat_peach();
 void  two_shuchu_sushu();
 void  three_zhifu_tongji_();
 void  four_print_shuixianhua_shu();
 void  five_search_themax_or_min_number();
 int main()
 {
     int n;
     scanf ("%d",&n);
     switch (n)
     {
         case 1:
          one_houzi_eat_peach();   
         break;
          case 2:
          two_shuchu_sushu();
          break;
           case 3:
           three_zhifu_tongji_();

           break;
            case 4:
            four_print_shuixianhua_shu();
            break;
            case 5:
            five_search_themax_or_min_number();
            break;
            if (n==6)
            break;
     }
     return 0;
 }
void  one_houzi_eat_peach()
{
    

    int i;
    int tao=1;
    for (i=0;i<9;i++)
    {
        tao+=1;
        tao*=2;

    }
    printf ("%d",tao);


}
void  two_shuchu_sushu()
{
 for (int i = 2; i>=100&&i<=200; ++i)
 {
  int flag = 1;

  for (int j = 2; j <= sqrt(i); ++j)
  {
   if (i%j == 0)
   {
    flag = 0;//用if来判定是否是素数
    break;
   }
  }

  if (flag)
  {
   printf("%d\n", i);
  }
 }
}
void  three_zhifu_tongji_()

{
 char c;
 int letterCnt = 0, spaceCnt = 0, numCnt = 0, otherCnt = 0;
 while ((c = getchar()) != '\n')
 {
  if ((c >= 'a'&&c <= 'z') || (c >= 'A'&&c <= 'Z'))
  {
   letterCnt++;
  }
  else if (c == ' ')
  {
   spaceCnt++;
  }
  else if (c >= '0'&&c <= '9')
  {
   numCnt++;
  }
  else
  {
   otherCnt++;
  }
 }

 printf("英文字母个数为%d\n", letterCnt);
 printf("空格个数为%d\n", spaceCnt);
 printf("数字个数为%d\n", numCnt);
 printf("其它字符个数为%d", otherCnt);

}
 void four_print_shuixianhua_shu()
{
 for (int i = 100; i < 1000; ++i)
 {
  int units, tens, huns;
  huns = i / 100;
  tens = i % 100 / 10;
  units = i % 10;
  if (i == huns*huns*huns + tens*tens*tens + units*units*units)
  {
   printf("%d ", i);
  }
 }

}
void  five_search_themax_or_min_number()
{
    int n;
    scanf ("%d",&n);
    int i;
    int a[100];
    for (i=0;i<n;i++)
    {
        scanf ("%d",&a[i]);
    }
    int max,min;
    max=min=a[0];
    int j;
    for (j=0;j<n;j++)
    {
        if (a[i]>max)
        {
            a[i]=max;

        }
        

    }
    int k;
    for (k=0;k<n;k++)
    {
        if (a[i]<min)
        {
            a[i]=min;

        }
        

    }
    printf ("max=%dmin=%d",max,min);

}
 


点击全文阅读


本文链接:http://zhangshiyu.com/post/37028.html

数为  素数  判定  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1