当前位置:   article > 正文

c上机题第二波

c上机题第二波

镜像字符串

输入:123456 输出:12345654321

#include<iostream>
#include<bits/stdc++.h>
void recursive(char *s, int i);
int main(){
   char s[256];
   gets(s);
   recursive(s,0);
   return 0;
}
void recursive(char *s, int i){
   if(s[i]=='\0')
      return;
   if(s[i+1]=='\0'){
      putchar(s[i]);
      return;
   }
   putchar(s[i]);
   
   
   recursive(s, i + 1);

   putchar(s[i]);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

输出偶数

#include<stdio.h>

int main(){
   int a[10];
   for (int i = 0; i < 10;i++)
      scanf("%d", &a[i]);

   for (int i = 0; i < 10; i++){
      if(a[i]%2==0){
         printf("%3d", a[i]);
      }
   }
   return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

递归统计整数出现的次数

#include<iostream>
#include<bits/stdc++.h>

void total(int a[],int n,int result[]){
   int m;
   
   //将结果数组归零 
   for (int i = 0; i < 10; i++)
   {
      result[i] = 0;
   }
   //统计1-9出现的数字次数 
   for (int i = 0; i < n;i++){
   	
      m = a[i];

      while (m)
      {
         result[m % 10]++;
         m /= 10;
      }
   }
}
int main()
{
   int a[64];//存储输入数字的数组
   int result[10];//计数数组
   int t;//临时输入的数字
   int n = 0;
   while (1)
   {
   	  scanf("%d",&t);
	if(t==0){
		break;
	} 
      a[n++] = t;
   }//n代表输入数字的个数

   total(a, n, result);
   
   //扫尾,输出结果 
   for (int i = 0; i < 10;i++){
   	if(result[i]!=0)
      printf("%d:%d\n", i, result[i]);
   }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/274755
推荐阅读
相关标签
  

闽ICP备14008679号