C语言10月15日作业

1、 字符串恢复
代码:
#include <stdio.h>
int main(){
char source[]=“lipps”;
char target[]=" “;
int i=0;
for(i=0;i<5;i++){
if(source[i]>‘d’)
{target[i]=source[i]-4;}
else{
target[i]=‘z’-(‘d’-source[i]);
}
}
printf(”%s",target);

return 0;

}

2、 排序
代码:
#include <stdio.h>
#include <stdlib.h>
int main(){
int data[]={5,6,3,21,-1,5,7,-9};
int i,j;
int temp;
for(i=0;i<7;i++)
{
for(j=i+1;j<8;j++)
{
if(data[i]>data[j]){
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
}
}
for(i=0;i<8;i++)
{
printf("%d,",data[i]);
}
return 0;
}

3、 矩阵的转置
代码:
#include<stdio.h>
int main()
{
int a[2][3]={{4,5,4},
{2,1,1}};
int b[3][2];
for(int j=0;j<3;j++)
{
for(int i=0;i<2;i++)
{
b[j][i]=a[i][j];
printf("%d\t",b[j][i]);
}
printf("\n");
}
return 0;
}

4、 姓名排序
代码:
#include <stdio.h>
#include <string.h>
int main()
{
char name[100][15]={
“向俊霖”,
“赵晨”,
“李东”
};
char tmp[15];
for (int i=0;i<2;i++)
{
for (int j=i+1;j<3;j++)
{
if (strcmp(name[i],name[j])>0)
{
strcpy(tmp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],tmp);
}
}
}
for (int x=0;x<3;x++)
{
printf("%s\n",name[x]);
}
return 0;
}

5、 单词数量统计
代码:
#include <stdio.h>
#include <string.h>
int main()
{
int sum=0;
char a[1000]=“Almost every child will complain about their parents sometimes. It is natural, because when people stay together for a long time, they will start to have argument. But ignore about the unhappy time, our parents love us all the time. No matter what happen to us, they will stand by our sides. We should be grateful to them and try to understand them.”;
for(int i=0;i<1000;i++)
{
if(a[i]==32)
{
sum=sum+1;
}
if(a[i]==a[i-1]&&a[i-1]==32)
{
sum=sum-1;
}
}
printf("%d",sum+1);
return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值