当前位置:网站首页>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;
}
边栏推荐
- Idea view bytecode configuration
- Supplier selection and prequalification of Oracle project management system
- Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
- MySql报错:unblock with mysqladmin flush-hosts
- Chrome用户脚本管理器-Tampermonkey 油猴
- Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
- 【Go实战基础】如何安装和使用 gin
- Chrome浏览器插件-Fatkun安装和介绍
- Say goodbye to 996. What are the necessary plug-ins in idea?
- [staff] common symbols of staff (Hualian clef | treble clef | bass clef | rest | bar line)
猜你喜欢
【Go实战基础】gin 如何设置路由
破茧|一文说透什么是真正的云原生
数构(C语言)——第四章、矩阵的压缩存储(下)
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
Cloud computing in my eyes - PAAS (platform as a service)
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
企业级SaaS CRM实现
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
Dix ans d'expérience dans le développement de programmeurs vous disent quelles compétences de base vous manquez encore?
[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
随机推荐
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
Mathematics in machine learning -- point estimation (I): basic knowledge
Enterprise level SaaS CRM implementation
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Solutions to Chinese garbled code in CMD window
长篇总结(代码有注释)数构(C语言)——第四章、串(上)
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
队列管理器running状态下无法查看通道
破茧|一文说透什么是真正的云原生
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
VIM操作命令大全
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
【Go实战基础】gin 高效神器,如何将参数绑定到结构体
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
The channel cannot be viewed when the queue manager is running
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
Mysql 多列IN操作
「面试高频题」难度大 1.5/5,经典「前缀和 + 二分」运用题