2019/12/20补档

C语言两道编程题

(1)编程实现凯撒加密法,将原来的小写字母用后三个字母的大写形式替换,x,y,z替换为a,b,c,大写字母同理。
要求:
(1)要在主函数里初始化字符串为"To Be successful, Be crazy first."
(2)写一个void kaisa(char
str)函数供主函数调用,用来对主函数里的字符串加密;
(3)在主函数里显示输出加密后的字符串。
*

/*第四题第一小题*/
#include<stdio.h>
void kaisa(char* str2);
int main()
{
	int i=0,y=0;
	char str1[] = { "To Be successful, Be crazy first." }, * str2;
	str2 = str1;
	kaisa(str1);
	while (str1[y] != '\0')
	{
		printf("%c", str1[y]);
		y++;
	}
}
void kaisa(char* str1)
{
	int x=0;
	for (x = 0; str1[x] != '\0'; x++)
	{
		
		
			if (str1[x] >= 'a' && str1[x] <= 'w')
			{
				str1[x] = str1[x] - 29;
				continue;
			}

			if (str1[x] >= 'A' && str1[x] <= 'W')
			{
				str1[x] = str1[x] + 35;
				continue;
			}
			if (str1[x] == 'y' || str1[x] == 'z' || str1[x] == 'x')
			{
				str1[x] = str1[x] - 55;
				continue;
			}
			if (str1[x] == 'Y' || str1[x] == 'Z' || str1[x] == 'X')
			{
				str1[x] = str1[x] + 9; 
				continue;
			}
		
		
	}
}

注意事项:
进行函数调用时,数据是从实参kaisa(str1)传到形参kaisa(char* str1),此题中,str1的数据被覆盖了。
(2)从主函数随机输入十个整数,调用函数找最小数,并在主函数输出最小值。

/*第四题第二小问*/
#include <stdio.h>
int xiao(int x,int a[10]);
int main()
{
	int a[10], i, y=0;
	printf("请输入十个整数\n");
	for (i = 0; i < 10; i++)
		scanf_s("%d", &a[i]);
	printf("最小值为%d\n", xiao(y,a));
	return 0;
}
int xiao(int x,int a[10])
{
	int k,t;
	a[10];
	k = a[0];
	for (t = 0; t < 10; t++)
		if (k > a[t])
			k = a[t];
	return k;
}

注意事项:形参与实参的定义必须一样。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值