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

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

 #include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void fun(char *ss)
{
int i;
for (i = ; ss[i]; i++)
{
if (i % == )
{
if (ss[i] >= 'a'&&ss[i] <= 'z')
{
ss[i] -= ;//转换成大写
}
}
}
}
void main()
{
FILE *wf;
char tt[],s[]="abc4Efg";
system("CLS");
printf("\nPlease enter an string within 80 characters:\n");
gets(tt);
printf("\n\nAfter changing, the string\n %s",tt);
fun(tt);
printf("\nbecomes\n %s\n",tt);
/******************************/
wf=fopen("out.dat","w");
fun(s);
fprintf (wf,"%s",s);
fclose(wf);
/*****************************/
}

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

 #include  <string.h>
#include <stdio.h>
void fun(char t[])
{
char c;
int i,j;
/*************found**************/
for(i=strlen(t)-;i;i--)指向最后一个元素
for(j=;j<i;j++)
/*************found**************/
if(t[j]>t[j+])
{
c= t[j];
t[j]=t[j+];
t[j+]=c;
}
}
void main()
{
char s[]; printf("\nPlease enter a character string :");
gets(s);
printf("\n\nBefore sorting :\n %s",s);
fun(s);
printf("\nAfter sorting decendingly:\n %s",s);
}

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

 #include  <stdio.h>
#define N 3
#define M 4
/**********found**********/
void fun(int (*a)[N], int k)
{ int i,temp ;
/**********found**********/
for(i = ; i < N ; i++)
{ temp=a[][i] ;
/**********found**********/
a[][i] = a[k][i];
a[k][i] = temp ;
}
}
void main()
{ int x[M][N]={ {,,},{,,},{,,},{,,} },i,j;
printf("The array before moving:\n\n");
for(i=; i<M; i++)
{ for(j=; j<N; j++) printf("%3d",x[i][j]);
printf("\n\n");
}
fun(x,);
printf("The array after moving:\n\n");
for(i=; i<M; i++)
{ for(j=; j<N; j++) printf("%3d",x[i][j]);
printf("\n\n");
}
}
上一篇:hdu_4352_XHXJ's LIS(数位DP+状态压缩)


下一篇:MySql下实现先排序后分组