问题描述:爱因斯坦出了一道数学题:有一条长台阶,若每步跨2阶,则最后剩1阶,若跨3,则剩2,若跨5,则剩4,若跨6,则剩5,若跨7,则不剩。问在1~N内,有多少数能满足?
流程图:
伪代码:
input N
for i<-1 to N
if i%2=1&&i%3=2&&i%5=4&&i%6=5&&i%7=0
output i
sum++
output sum
代码:
#include <iostream>
using namespace std;
int main()
{
int i,sum=0,N;
cin>>N;
for(i=1;i<=N;i++)
{
if((i%2==1)&&(i%3==2)&&(i%5==4)&&(i%6==5)&&(i%7==0))
{
cout<<i<<" ";
sum++;
}
}
cout<<endl<<sum<<"个";
}
标签:cout,int,sum,&&,打卡,i% From: https://www.cnblogs.com/chukjbgg333/p/17426160.html