有人可以解释这个算法的作用吗? [英] Can someone please explain what this algorithm does?

查看:87
本文介绍了有人可以解释这个算法的作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 set count1 = 0 
set count2 = 0
读取数字

读取成功时执行
如果数字mod 2等于0
然后
设置count1 = count1 + 1
否则
如果数字div 7等于0
然后
set count2 = count2 + 1
读取数字
写入计数1
写入计数2





我尝试过:



我尝试使用一个随机数来看看我能算出来但是如果数字Mod 2或Div 7不是= 0会发生什么? br />


那么出于某种原因还有第二个输入数字?对不起,我对这一切都很陌生。

解决方案

我在下面的评论中的解释



/ /初始化变量并设置为0它出现

set count1 = 0

set count2 = 0



//读取用户输入

读取数字





// while / do循环说只要收集用户输入成功,继续下面的代码

,同时阅读成功了



//说出输入的数字除以2,如果余数为0 ...增加count1乘1

如果数字mod 2等于0



set count1 = count1 + 1

否则



//看起来像if else声明的其他内容

//说如果数字%2!= 0 - >看看数字除以7是否等于0.我不确定这是模数还是除数

//如果数字/ 7 == 0则将count2递增1。 br />
如果数字div 7等于0

那么

set count2 = count2 + 1



我想这会保持while / do循环,所以在这里你读取另一个数字并再次运行这个过程

读取数字



//显示你的变量计数,我假设,一旦while / do循环被打破而没有输入用户输入

写入计数1

写入计数2


提示

如果数字mod 2等于0 

set count1 = count1 + 1





计算均匀(完全可被2整除)数字(因为,你知道,如果提醒返回零,则被除数完全除以除数)。


set count1 = 0
set count2 = 0
read number

while read was successful do
      if number mod 2 equals 0
      then
            set count1 = count1 + 1
      otherwise
      if number div 7 equals 0
      then
            set count2 = count2 + 1
read number
write count1
write count2



What I have tried:

I tried using a random number to see if i could figure it out but what's suppose to happen if the number Mod 2 or Div 7 doesn't = 0?

Then there's a second input number for some reason? Sorry i'm very new to all of this.

解决方案

My interpretation in comments below

// Initializing your variables and setting to 0 it appears
set count1 = 0
set count2 = 0

//Read user input
read number


// A while/do loop saying as long as the gathering of the user input was successful, proceed with the code below
while read was successful do

// Saying if the number entered divided by 2, if the remainder is 0... increment count1 by 1
if number mod 2 equals 0
then
set count1 = count1 + 1
otherwise

// Seems like the else of an if else statement
// Says if number % 2 != 0 -> see if the number, divided by 7 is equal to 0. Im not sure if this is meant to be modulus or division
// If number / 7 == 0 then increment the count2 by 1.
if number div 7 equals 0
then
set count2 = count2 + 1

I guess this keeps the while/do loop going so here you read another number and run it through this process again
read number

// Display the counts of your variables, I assume, once the while/do loop has been broken out of by not entering a user input
write count1
write count2


Hint

if number mod 2 equals 0
      then
         set count1 = count1 + 1



counts even (exactly divisible by two) numbers (because, you know, if the reminder returns zero, then the dividend is exactly divided by the divisor).


这篇关于有人可以解释这个算法的作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆