zoukankan      html  css  js  c++  java
  • C语言作业7

    1. 编写程序计算自己名字中包含字母表中每个字母的个数

    #include<stdio.h>
    #include<string>
    #include<cstring>
    int main()
    {
        char a[999];
        int b[999];
        char c='A';
        for(int i=0;i<30;i++)
        {
            b[i]=0;
        }
        scanf("%s",a);
        for(int i=0;i<strlen(a);i++)
        {
            if(a[i]=='a')
                b[0]++;
            if(a[i]=='b')
                b[1]++;
            if(a[i]=='c')
                b[2]++;
            if(a[i]=='d')
                b[3]++;
            if(a[i]=='e')
                b[4]++;
            if(a[i]=='f')
                b[5]++;
            if(a[i]=='g')
                b[6]++;
            if(a[i]=='h')
                b[7]++;
            if(a[i]=='i')
                b[8]++;
            if(a[i]=='j')
                b[9]++;
            if(a[i]=='k')
                b[10]++;
            if(a[i]=='l')
                b[11]++;
            if(a[i]=='m')
                b[12]++;
            if(a[i]=='n')
                b[13]++;
            if(a[i]=='o')
                b[14]++;
            if(a[i]=='p')
                b[15]++;
            if(a[i]=='q')
                b[16]++;
            if(a[i]=='r')
                b[17]++;
            if(a[i]=='s')
                b[18]++;
            if(a[i]=='t')
                b[19]++;
            if(a[i]=='u')
                b[20]++;
            if(a[i]=='v')
                b[21]++;
            if(a[i]=='w')
                b[22]++;
            if(a[i]=='x')
                b[23]++;
            if(a[i]=='y')
                b[24]++;
            if(a[i]=='z')
               b[25]++;
        }
        for(int i=0;i<26;i++)
            {
               putchar(c);printf(":%d个
    ",b[i]);
               c=c+1;
            }
    }

    2.编写程序将给定的n(小于10)个整数存入数组中,将数组中的这n个数逆序存放,再按顺序输出数组中的元素。 

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
        int a[10],n,b[10],i,s=32;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=1;i<=n;i++)
        {
            b[i]=a[n-i+1];
        }
        for(i=1;i<=n;i++)
        {
            printf("%d%c",b[i],s);
        }
        printf("
    ");
        return 0;
    }

    3. 编写程序找出给定两个整型数组的共有元素

    #include<stdio.h>
    #include<string>
    #include<cstring>
    int main()
    {
       int a[999];
       int b[999];
       int m,n;
       scanf("%d",&n);
       for(int i=0;i<n;i++)
       {
           scanf("%d",&a[i]);
       }
       scanf("%d",&m);
       for(int i=0;i<m;i++)
       {
           scanf("%d",&b[i]);
       }
       for(int i=0;i<n;i++)
       {
           for(int j=0;j<m;j++)
           {
               if(a[i]==b[j])
                {
                    printf("%d ",a[i]);
                    break;
                }
           }
       }
    }

    4. 编写递归函数将某个整数按反序方式输出

    #include<stdio.h>
    #include<string>
    #include<cstring>
    int fanxu(int a)
    {
        printf("%d",a%10);
        if(a>9)
            fanxu(a/10);
    }
    int main()
    {
       int a;
       scanf("%d",&a);
       fanxu(a);
       printf("
    ");
    }

    前两次作业都没有认真写所以得的分数也不高,这次请教了很多人,发动了整个朋友圈,终于搞懂了,自己写的跟同学写的也太一样,觉得同学写的实在是太好了,尤其是伍鹏的输入名字那道题,简直是太厉害了,还把英文大小写分开了,以后再也不会不认真写作业了糊弄事,要向身边的同学学习。

  • 相关阅读:
    进程对象的属性或方法详解
    进程理论以及开启子进程的两种方式
    计算机发展史(多道技术)
    基于socketserver实现的并发(tcp和udp)
    基于udp协议的套接字及udp协议粘包问题
    模拟ssh的远程网络传输
    周考题目及答案
    c/s架构搭建
    网络编程基础
    10.16模拟赛(湖南集训)
  • 原文地址:https://www.cnblogs.com/ljxsol/p/6053797.html
Copyright © 2011-2022 走看看