yangbaowen 发表于 2022-5-22 12:31:36

用c语言编写,完成下列题目

1、将一个3×4二维数组中每一行的值按逆序重新存放,例如原来的顺序为:{1,2,3,4,5,6,7,8,9,10,11,12},要求改为:{4,3,2,1,8,7,6,5,12,11,10,9}。
2、输入一行字符,编程统计出其中大写字母,小写字母,数字,空格和其他字符各是多少个?
3、请编写一个求整数绝对值的函数,要求在主函数中输入数据,然后调用你自己写的绝对值函数求该数的绝对值并输出。
4、请编写一个求两个实数乘法的函数,要求在主函数中输入数据,然后调用你自己写的函数求所输入数据的相乘结果并输出。
5、写一个函数,使输入的一个字符串按反序存放,如输入CHINA,输出ANICH。在主函数中输入和输出字符串。
6、写一个函数,使得给定的一个3*3的二维整型数组转置,即行列互换。
7、写一个函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字间空一个空格。如输入2016,应输出“2 0 1 6”。

jhq999 发表于 2022-5-22 12:31:37

本帖最后由 jhq999 于 2022-5-22 15:45 编辑


void change(int *mt,int m,int n)/////////(1)
{
        int i=0,j=0,tmp=0;
        for(i=0;i<m;i++)
        {
                for(j=0;j<n/2;j++)
                {
                        tmp=mt;
                        mt=mt;
                        mt=tmp;
                }
        }
}



int i=0,bigcount=0,lowcount=0,spacecount=0,numcount=0,othercount=0;
while(str)
{
        if(str>='a'&&str<='z')bigcount++;
        else if(str>='A'&&str<='Z')lowcount++;
        else if(str>='0'&&str<='9')numcount++;
        else if(0x20==str)spacecount++;
       
        i++;
}
othercount=i- bigcount-lowcount-spacecount-numcount;


////template <class T>
double abs(double n)
{
        return n<0?-1*n:n;
}
double mul(double a,double b)
{
        return a*b;
}


void invertstr(char* str)
{
        int len=0;
        while(str)len++;
        for(int i=0;i<len/2;i++)
        {
                str=str;
                str=str;
                str=str;
        }
        str='\0';
}



void invertmt(int (*mt))
{
           for (int i = 0; i < 3;i++)
           {
                   for (int j = i+1; j < 3; j++)
                   {
                           int t=mt;
                           mt=mt;
                           mt=t;
                   }
           }
}


void outputstr(char* str)
{
        int i=0;
        do
        {
                printf("%c",str);
                printf("%c",0x20);
                i++;
        }while(str);
        printf("%c",str);
}

yangbaowen 发表于 2022-5-22 15:25:53

jhq999 发表于 2022-5-22 13:08


你用的是什么编译器啊

jhq999 发表于 2022-5-22 15:27:23

本帖最后由 jhq999 于 2022-5-22 15:31 编辑

yangbaowen 发表于 2022-5-22 15:25
你用的是什么编译器啊

有什么问题吗?这些代码里面好像没有和编译器有关系的,模板那个我也改了,c里面没有模板

yangbaowen 发表于 2022-5-22 15:37:00

jhq999 发表于 2022-5-22 15:27
有什么问题吗?这些代码里面好像没有和编译器有关系的,模板那个我也改了,c里面没有模板

但是我用Devc++,报错了

jhq999 发表于 2022-5-22 15:39:09

本帖最后由 jhq999 于 2022-5-22 15:43 编辑

那个报错了,我没用编译器,直接在回复里写的。可能有的写错了变量名,有的我只写了只要功能。

yangbaowen 发表于 2022-5-22 15:57:21

jhq999 发表于 2022-5-22 15:39
那个报错了,我没用编译器,直接在回复里写的。可能有的写错了变量名,有的我只写了只要功能。

都报错了

jhq999 发表于 2022-5-22 16:59:52

本帖最后由 jhq999 于 2022-5-22 17:16 编辑

yangbaowen 发表于 2022-5-22 15:57
都报错了

你不会自己没写主函数吧
void change(int *mt,int m,int n)/////////(1)
{
      int i=0,j=0,tmp=0;
      for(i=0;i<m;i++)
      {
                for(j=0;j<n/2;j++)
                {
                        tmp=mt;
                        mt=mt;
                        mt=tmp;
                }
      }
}
int main()
{
        int mt={1,2,3,4,5,6,7,8,9,10,11,12};
        change(mt,3,4);
        for (int i = 0; i < 12; i++)
        {
                if (0==i%4)
                {
                        printf("\n");
                }
                printf("%4d ",mt);
               
               
        }
        return 0;
}
int main()
{
        char str="abc fff#A b 1234 5%&";
        int i=0,bigcount=0,lowcount=0,spacecount=0,numcount=0,othercount=0;
        while(str)
        {
                if(str>='a'&&str<='z')lowcount++;
                else if(str>='A'&&str<='Z')bigcount++;
                else if(str>='0'&&str<='9')numcount++;
                else if(0x20==str)spacecount++;

                i++;
        }
        othercount=i- bigcount-lowcount-spacecount-numcount;
        printf("%d %d %d %d %d",bigcount,lowcount,spacecount,numcount,othercount);
        return 0;
}
double abs(double n)
{
      return n<0?-1*n:n;
}
int main()
{
        int a=-4;
        float b=-3.7f;
        double c=7;
        printf("%lf %lf %lf",abs(a),abs(b),abs(c));
        return 0;
}
double mul(double a,double b)
{
      return a*b;
}
int main()
{
       
        printf("%lf",mul(4.2,5.1));
        return 0;
}
void invertstr(char* str)
{
      int len=0;
      while(str)len++;
      for(int i=0;i<len/2;i++)
      {
                str=str;
                str=str;
                str=str;
      }
      str='\0';
}


int main()
{
       
        char str="abcdefg";
        invertstr(str);
        printf("%s",str);
        return 0;
}
void invertmt(int (*mt))
{
         for (int i = 0; i < 3;i++)
         {
                   for (int j = i+1; j < 3; j++)
                   {
                           int t=mt;
                           mt=mt;
                           mt=t;
                   }
         }
}


int main()
{
       
        int str={1,2,3,4,5,6,7,8,9};
        invertmt(str);
        for (int i = 0; i < 3; i++)
        {
                for (int j = 0; j < 3; j++)
                {
                        printf("%4d",str);
                }
                printf("\n");
        }
        return 0;
}
void outputstr(char* str)
{
      int i=0;
      do
      {
                printf("%c",str);
                printf("%c",0x20);
                i++;
      }while(str);
         printf("%c",str);
}



int main()
{
        char str;
        scanf("%s",str);
        outputstr(str);
        return 0;
}

yangbaowen 发表于 2022-5-22 17:15:47

jhq999 发表于 2022-5-22 16:59
你不会自己没写主函数吧

额,没有。

jhq999 发表于 2022-5-22 17:19:34

yangbaowen 发表于 2022-5-22 17:15
额,没有。

我想偷个懒都不成{:5_104:}

hornwong 发表于 2022-5-24 00:02:20

{:5_106:}
页: [1]
查看完整版本: 用c语言编写,完成下列题目