PTA7-25~27

25求奇数和
#include<stdio.h>
int main()
{
	int n,total=0;
	scanf("%d ", &n);
	while (n > 0)
	{
		if(n%2!=0)
		total += n;
		scanf("%d", &n);
	}
	printf("%d", total);
	return 0;
}

26求最大公约数和最小公倍数
#include<stdio.h>
int main()
{
	int M,N;
	scanf("%d %d", &M,&N);
	int max, min,f;
	f = M * N;
		while(max = M % N)//辗转相除法求最大公约数
		{
			M = N;
			N = max;
		}
		min = f / N;//注意f
//最小公倍数=两个数乘积除以最大公约数
		printf("%d %d", N,min);//最后的N是最大公约数

	return 0;
}

27兔子繁衍
#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    int yes=0, total=1, temple;//yes表示生的,total表示总的,temple表示交换
    int month = 1;
    while (total < N) {
        month++;
        temple = yes;
        yes = total;
       total+=temple;
    }
    printf("%d", month);
    return 0;
}

月份yes(生)不生total(总)
1011
2011
3112
4123
5134
6347
73610

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,pta7-25买U盘误差修正的问题可能涉及到处理汉字输出和浮点数的处理。在给出的代码中,使用了二维数组来保存汉字字符,通过索引来输出相应的汉字。对于浮点数的处理,使用了四舍五入的方法来修正误差。具体的代码实现如下: ```cpp #include <bits/stdc++.h> using namespace std; char a1\[10\]\[5\] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; char s1\[11\]\[5\] = {"分","角","元","拾","佰","仟","万","拾","佰","仟","亿"}; int main() { int t = 0, i; double a, b; char s\[40\]; cin >> a >> b; double c = a * b + 0.00004; printf("单价: %.2f元/克\n", a + 0.00004); printf("重量: %.2f克\n", b + 0.00004); printf("金额: %.2f元\n", c); printf("大写: "); sprintf(s, "%.2lf", c); for (int i = 0; s\[i\]; i++) { if (s\[i\] == '.') break; t++; } for (i = 0; s\[i\]; i++) { if (s\[i\] == '.') break; printf("%s%s", a1\[s\[i\] - '0'\], s1\[t + 1\]); t--; } printf("%s角%s分\n", a1\[s\[i + 1\] - '0'\], a1\[s\[i + 2\] - '0'\]); return 0; } ``` 这段代码可以计算出给定单价和重量的金额,并将金额以大写的形式输出。同时,还修正了浮点数的误差。 #### 引用[.reference_title] - *1* *2* [PTA:7-137 出售金项链(误差修正版) (10分)](https://blog.csdn.net/weixin_43581819/article/details/104144588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [PTA 7-25 买U盘(误差修正版)](https://blog.csdn.net/peng_papa/article/details/126748424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值