当前位置:网站首页>C语言之分草莓
C语言之分草莓
2022-07-02 06:34:00 【FF小迷糊吖~】
四个朋友去采摘园摘草莓,劳动了一上午感觉很累,就约定先去睡觉,睡醒后再一起平分这些草莓。有一个人醒得早,等了一会儿也没见其它人过来,就先拿了一个草莓吃了,又等了一会儿还没见其它人过来,就把剩下的草莓分成了四等份(恰好等分),拿走了其中的一份。之后第二个人醒了,也是先吃了一个草莓,但是他不知道已经有人拿走了一部分草莓,就把剩下的草莓又等分成四份(恰好等分),拿走了其中的一份。之后第三个人、第四个人也是如此。请问这堆草莓共有多少个?
编写程序,输出10组满足题目要求的数值,要求必须从满足题目要求的最小数值开始,依次增加,中间不能跳过其它满足要求的数值,每个数值占一行。如满足要求的最小数值是253,满足要求的第二小数值是509,……,则输出为:
253
509
……
编程要求:
1、请使用循环的方法实现;
2、任务提交代码时需保证其符合行业代码规范,需进行必要的缩进及换行。(影响成绩评定)
#include <stdio.h>
int main(void)
{
int n;
int c = 0;
for(n = 1;;n++){
if((n-1)%4 == 0)
if(((n-1)*3/4-1)%4 == 0)
if((((n-1)*3/4-1)*3/4-1)%4 == 0)
if(((((n-1)*3/4-1)*3/4-1)*3/4-1)%4 == 0){
printf("%d\n",n);
c++;
if(c > 9)
break;
}
}
return 0;
}
#include <stdio.h>
int main(void)
{
int i,a,b,c,d;
i=0;
a=6;
while(i<10){
b=(a-1)*3/4;
c=(b-1)*3/4;
d=(c-1)*3/4;
if((a-1)%4==0 && (b-1)%4==0 && (c-1)%4==0 && (d-1)%4==0){
printf("%d\n",a);
i+=1;
}
a+=1;
}
return 0;
}
边栏推荐
- Microservice practice | teach you to develop load balancing components hand in hand
- Matplotlib剑客行——容纳百川的艺术家教程
- 微服务实战|熔断器Hystrix初体验
- VIM操作命令大全
- The channel cannot be viewed when the queue manager is running
- Watermelon book -- Chapter 5 neural network
- CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
- Cartoon rendering - average normal stroke
- Redis installation and deployment (windows/linux)
- 【Go实战基础】如何安装和使用 gin
猜你喜欢

Troubleshooting and handling of an online problem caused by redis zadd

Break the cocoon | one article explains what is the real cloud primordial

【Go实战基础】gin 如何获取 GET 和 POST 的请求参数

西瓜书--第五章.神经网络

Mysql 多列IN操作

Supplier selection and prequalification of Oracle project management system

西瓜书--第六章.支持向量机(SVM)

互联网API接口幂等设计

微服务实战|声明式服务调用OpenFeign实践

Matplotlib剑客行——初相识Matplotlib
随机推荐
远程连接IBM MQ报错AMQ4036解决方法
JDBC回顾
MySQL multi column in operation
Matplotlib剑客行——初相识Matplotlib
In depth analysis of how the JVM executes Hello World
Break the cocoon | one article explains what is the real cloud primordial
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
What are the differences between TP5 and laravel
Microservice practice | teach you to develop load balancing components hand in hand
Matplotlib剑客行——容纳百川的艺术家教程
Redis sorted set data type API and application scenario analysis
Insight into cloud native | microservices and microservice architecture
Redis zadd导致的一次线上问题排查和处理
【Go实战基础】gin 如何设置路由
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
自定義Redis連接池
Knife4j 2.X版本文件上传无选择文件控件问题解决
记录下对游戏主机配置的个人理解与心得
The channel cannot be viewed when the queue manager is running