第十次上机实验

任务1

#include<stdio.h>  
#define N 100  
void getx(char *c1);  
void getr(char *c2);  
void main()  
{char a[N];  
puts("Enter a string:");  
gets(a);  
getx(a);  
}  
void getx(char *c1)  
{int n,k=0;int j=0;char temp[N];  
puts("Enter an integer:");  
scanf("%d",&n);  
while(*(c1+j)!='\0')    
{j++;}   
for(int i=j-n;i<j;i++)    
{temp[k]=*(c1+i);  
k++;}   
temp[k]='\0';  
getr(temp);  
puts("The new string is ");  
puts(temp);  
}  
void getr(char *c2)   
{int i=0;    
char temp[N];    
while(*(c2+i)!='\0')    
{i++;}    
for(int j=0;j<i;j++)    
{temp[i-j-1]=*(c2+j);}    
for(int k=0;k<i;k++)    
{*(c2+k)=temp[k];}    
}  

任务2

#include<stdio.h>  
#define N 100  
int j(int*x,int n);  
int s(int*x,int n);  
void main()  
{int a[N];  
int n=0,i=0;  
printf("请输入一组整数:\n");  
while(1)  
{scanf("%d",&a[i]);  
i++;  
n++;  
if(getchar()=='\n')  
break;}  
j(a,n);  
s(a,n);  
}  
int j(int*x,int n)  
{int temp=NULL;  
int i,j;  
for(j=0;j<n;j++)  
{  
    for(i=0;i<n-1;i++)  
    {if(*(x+i)<*(x+i+1))  
    {temp=*(x+i);  
    *(x+i)=*(x+i+1);  
    *(x+i+1)=temp;}  
    }  
}  
printf("由大到小:\n");  
for(j=0;j<n;j++)  
{printf("%d ",*(x+j));}  
printf("\n");  
return 0;}  
int s(int*x,int n)  
{int temp=NULL;  
int i,j;  
for(j=0;j<n;j++)  
{  
    for(i=0;i<n-1;i++)  
    {if(*(x+i)>*(x+i+1))  
    {temp=*(x+i);  
    *(x+i)=*(x+i+1);  
    *(x+i+1)=temp;}  
    }  
}  
printf("由小到大:\n");  
for(j=0;j<n;j++)  
{printf("%d ",*(x+j));}  
printf("\n");  
return 0;}  


任务3

#include<stdio.h>     
#define N 20    
void p(char*p);    
void main()    
{char a[N];    
puts("输入字符串:");    
gets_s(a);    
p(a);    
}    
void p(char*p)    
{char b[N];    
int i=0;    
while(*p!='\0')    
{if(*p>=65&&*p<=90||*p>=97&&*p<=122)    
{b[i]=*p;    
i++;}    
p++;}    
b[i]='\0';    
puts(b);    
}    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值