C语言:将ss所指字符串中所有下标为奇数位置的字母转换为大写-将该字符串中的所有字符按ASCII码值升序排序后输出。-将a所指的4*3矩阵第k行的元素与第0行元素交换。...

//函数fun:将ss所指字符串中所有下标为奇数位置的字母转换为大写,若不是字母,则不转换。

 1 #include<conio.h>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 void fun(char *ss)
 6 {
 7     int i;
 8     for (i = 0; ss[i]; i++)
 9     {
10         if (i % 2 == 1)
11         {
12             if (ss[i] >= 'a'&&ss[i] <= 'z')
13             {
14                 ss[i] -= 32;//转换成大写
15             }
16         }
17     }
18 }
19 void main()
20 {
21   FILE *wf;
22   char tt[81],s[81]="abc4Efg";
23   system("CLS");
24   printf("\nPlease enter an string within 80 characters:\n");
25   gets(tt);
26   printf("\n\nAfter changing, the string\n  %s",tt);
27   fun(tt);
28   printf("\nbecomes\n %s\n",tt);
29 /******************************/
30   wf=fopen("out.dat","w");
31   fun(s);
32   fprintf (wf,"%s",s);
33   fclose(wf);
34 /*****************************/
35 }

//函数fun功能:读入一个字符串,将该字符串中的所有字符按ASCII码值升序排序后输出。

 1 #include  <string.h>
 2 #include  <stdio.h>
 3 void fun(char  t[])
 4 {
 5  char c;
 6  int i,j;
 7  /*************found**************/
 8  for(i=strlen(t)-1;i;i--)指向最后一个元素
 9      for(j=0;j<i;j++)
10         /*************found**************/
11       if(t[j]>t[j+1])
12           {
13            c= t[j];
14            t[j]=t[j+1];
15            t[j+1]=c;
16           }
17 }
18 void main()
19 {
20  char  s[81];
21  
22  printf("\nPlease  enter a character string :");
23  gets(s);
24  printf("\n\nBefore sorting :\n  %s",s);
25  fun(s);
26  printf("\nAfter sorting decendingly:\n %s",s);
27 }

//函数fun:将a所指的4*3矩阵第k行的元素与第0行元素交换。

 1 #include  <stdio.h>
 2 #define   N   3
 3 #define   M   4
 4 /**********found**********/
 5 void fun(int (*a)[N], int k)
 6 { int i,temp ;
 7 /**********found**********/
 8   for(i = 0 ; i < N ; i++)
 9   { temp=a[0][i] ;
10 /**********found**********/
11     a[0][i] = a[k][i];
12     a[k][i] = temp ;
13   }
14 }
15 void main()
16 { int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j;
17   printf("The array before moving:\n\n");
18   for(i=0; i<M; i++)
19   {  for(j=0; j<N; j++) printf("%3d",x[i][j]);
20      printf("\n\n");
21   }
22   fun(x,2);
23   printf("The array after moving:\n\n");
24   for(i=0; i<M; i++)
25   {  for(j=0; j<N; j++) printf("%3d",x[i][j]);
26      printf("\n\n");
27   }
28 }

 

转载于:https://www.cnblogs.com/ming-4/p/10462348.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值