任务一:
我的程序:
#include "stdafx.h"
#include "string.h"
#define N 100
void main()
{
char str[N],pb[N];
int a,i;
printf ("输入一个字符串");
gets_s(str,N);
printf ("\n");
printf ("输入一个整数");
scanf_s("%d",&a);
for (i=0;i<=(a-1);i++)
*(pb+i)=*(str+i);
*(pb+i)='\0';
puts(pb);
}
任务二:
#include "stdafx.h"
#include "string.h"
#define N 100
void fun( char *ss)
{
int i=0;
char temp=NULL;
while(*(ss+i)!='\0')
{
i++;
}
for(int j=1;j<=i/2;j++)
{
temp=*(ss+j-1);
*(ss+j-1)=*(ss+i-j);
*(ss+i-j)=temp;
}
}
void main()
{
char sr[N];
gets_s(sr,N);
void fun (char *ss);
fun (sr);
puts(sr);
}
任务三:
#include "stdafx.h"
#include "string.h"
int max(int *x,int *y,int *z);
int max(int *x,int *y,int *z)
{
if(*x>*y&&*x>*y)
return *x;
else if(*y>*x&&*y>*z)
return *y;
else if(*z>*x&&*z>*y)
return *z;
}
void main()
{
int a[4][3];
printf ("输入四组数字,每组三个\n");
for (int i=0;i<=3;i++)
{
scanf_s("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
}
for (int i=0;i<=3;i++)
{
printf ("最大数:%d\n",max(&a[i][0],&a[i][1],&a[i][2]));
}
}
任务四:
#include "stdafx.h"
#include "string.h"
#define N 100
void main()
{
int i=0,j=0;
char str[N],num[N],*p;
printf ("请输入");
gets_s(str);
while (str[i]!='\0')
{
i++;
}
for (p=str;p<str+i;p++)
{
if (*p>=48&&*p<=57)
{
num[j]=*p;
j++;
}
}
num[j]='\0';
puts(num);
}