第六天c基础作业

  1. 求一维数组中的第二大值
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(int argc, const char *argv[])
    {	
    	int a[5]={};
    	for(int i=0;i<5;i++)
    	{
    	scanf("%d",&a[i]);
    
    	}
    	for(int j=1;j<5;j++)
    	{
    	 	for(int i=0;i<5-j;i++)
    		{
    			if(a[i]<a[i+1])
    			{
    				int m= a[i];
    				a[i]=a[i+1];
    				a[i+1]=m;
    			}
    
    		}
    	}
    		printf("第二大值是:%d\n",a[1]);
    	return 0;
    }
    
    输出:
    12 32 44 11 2
    第二大值是:32
    

  2. 终端输入带空格的字符串,删除字符中的空格
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(int argc, const char *argv[])
    {		
    	char str[10]={};
    	int n=0;
    	gets(str);
    	for(int i=0;i<10;i++)
    	{
    		if(str[i]==' ')
    		{
    			for(int j=i;j<10;j++)
    			{
    				str[j]=str[j+1]; 
    			}
    		}
    
    	}
    
    	puts(str);
    	return 0;
    }
    
    输入:
    qdw fwd	 
    输出:
    qdwfwd

  3. 自己实现剩余的string函数族函数,strcat、strcpy、strcmp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[])
{		
	char a[]="hello";
	char b[]="world";
	printf("%s\n",strcpy(a,b));
	 printf("%ld\n",strlen(a));
	 printf("%d\n",strcmp(a,b));
	 printf("%s\n",strcat(a,b));
	 return 0;
}
输出:
world
5
0
worldwolld

4.整理思维导图

 

5.终端输入10个学生成绩,使用冒泡排序对学生成绩从低到高排序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[])
{		
 	int a[10]={};
	for(int i=0;i<10;i++)
	{
		scanf("%d",&a[i]);
	}
	int len=sizeof(a)/sizeof(int);
	for(int i=1;i<len;i++)
	{
		for(int j=0;j<len-i;j++)
		{
			if(a[j]>a[j+1]) 
			{
				int m=a[j];
				a[j]=a[j+1];
				a[j+1]=m;
			}
		}
	}
	for(int i=0;i<len;i++)
	{
		printf("%d ",a[i]);
	}
		putchar(10);
	return 0;
}
输入:
99 82 32 55 68 87 94 83 99 100
输出:
32 55 68 82 83 87 94 99 99 100 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值