目录
1.移动字母
2.拆分实数的整数与小数部分
3.查找星期
4.字符串的连接
5.使用函数实现字符串部分复制
6 判断回文字符串
*7.按等级统计学生成绩
* 8.指定位置输出字符串
* 9.计算职工工资
*10.输出学生成绩
11.找出总分最高的学生
12.计算平均成绩
*13.循环移动
*14.找最大的字符串
*15.删除字符串中指定字母
void Shift( char s[] )
{
char a[3];
int i,j;
for(i = 0; i < 3;i++)
a[i] = s[i];
for(i=3;s[i]!='\0'; i++)
s[i-3]=s[i];
for(j=i-3, i = 0; i < 3;i++,j++)
s[j] = a[i];
}
void splitfloat( float x, int *intpart, float *fracpart )
{
int y=(int)x;
float z;
*intpart=y;
z=(x-(int)x);
*fracpart=z ;
return;
}
int getindex( char *s )
{
int result = -1;
if(strcmp(s,"Monday")==0)
result = 1;
if(strcmp(s,"Tuesday")==0)
result = 2;
if(strcmp(s,"Wednesday")==0)
result = 3;
if(strcmp(s,"Thursday")==0)
result = 4;
if(strcmp(s,"Friday")==0)
result = 5;
if(strcmp(s,"Saturday")==0)
result = 6;
if(strcmp(s,"Sunday")==0)
result = 0;
return result;
}
char *str_cat( char *s, char *t )
{
char *one = s;
while(*s !='\0')
{
s++;
}
for(;*t!='\0';s++,t++)
{
*s = *t;
}
*s = '\0';
return one;
}
void strmcpy( char *t, int m, char *s )
{
int len = strlen(t);
char*p = m+t-1;
if(m>len)
*s = NULL;
while(*p!='\0')
{
*s = *p;
s++;
p++;
}
*s = '\0';
return s;
}
置为空指针时,是指针指向的值置为空 *s = NULL
bool palindrome( char *s )
{
int flat = 1;
int len = strlen(s);
for(int i = 0;i
int set_grade( struct student *p, int n )
{
int count = 0;
int i = 0;
for(i=0;i=60&&(*p).score<=69)
(*p).grade = 'C';
else if((*p).score>=70&&(*p).score<=84)
(*p).grade = 'B';
else
(*p).grade = 'A';
p++;
}
return count;
}
//法一:
char *match( char *s, char ch1, char ch2 )
{
int i=0;
char *p;
for(;(i
优先考虑方法4
#include
typedef struct work
{
char name[100];
float base;
float fdgz;
float expend;
float sum;
}WORK;
int main()
{
WORK s[10000];
int n, i,j;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%s", &s[i].name);
scanf("%f", &s[i].base);
scanf("%f", &s[i].fdgz);
scanf("%f", &s[i].expend);
s[i].sum = (s[i].base + s[i].fdgz)-s[i].expend;
}
for (j = 0; j < n;j++)
{
printf("%s %.2f\n", s[j].name, s[j].sum);
}
return 0;
}
#include
#include
int main()
{
int i,n;
int *p;
scanf("%d",&n);
p = (int*)malloc(sizeof(int)*n);
float sMax,sMin,sSum = 0;
float sAvg;
for(i = 0;i*(p+i))
sMin = *(p+i);
}
sSum += *(p+i);
}
sAvg = sSum/n;
printf("average = %.2f\n",sAvg);
printf("max = %.2f\n",sMax);
printf("min = %.2f",sMin);
return 0;
}
#include
typedef struct student
{
char number[100];
char name[100];
int math;
int english;
int chinese;
int sum;
}student;
int main()
{
struct student s[100];
int i,j,n,k;
scanf("%d",&n);
for(i=0;imax)
{
max = s[j].sum;
k = j;
}
}
printf("%s %s %d",s[k].name,s[k].number,s[k].sum);
return 0;
}
#include
struct student{
char num[6];
char name[10];
int score;
};
int main (){
struct student A[10];
int n,i,sum=0;
scanf("%d\n",&n);
for(i=0;i
#include
#include
void move(int *x,int n,int m)
{
int i;
printf("After move:");
for(i=n-m;i
#include
#include
#define MAX 5
#define MAX_LINE 10
int main()
{
int i,j;
char name[MAX][MAX_LINE];
char temp[2][100];
for (i = 0; i < MAX; i++)
scanf("%s", &name[i]);
strcpy(temp[0],name[0]);
//printf("%s", temp[0]);
for (i = 1; i < MAX; i++)
if(strcmp(temp[0],name[i]) < 0)
strcpy(temp[0],name[i]);
printf("Max is:");
printf(" %s", temp[0]);
return 0;
}
#include
#include
int main()
{
char ch[100];
int i,k,j=0;
char ah[100];
gets(ch);
k=strlen(ch);
for(i=0;i
#include
int main()
{
char a[100],*n,*m;
gets(a);
for(n=&a[0],m=&a[0]; *n != '\0';n++)//n=&a[0]把首地址赋值给n(或n=a)
if(*n != 'a') *m++ =*n; //*m++ =*n; 相当于*m =*n;m++;
*m = *n;
puts(a);
return 0;
}
#include
#include
void main()
{
char a[100],*p;
int v,i,u;
scanf("%s",a);
p=a;
v=strlen(p);
for(i=0;i