编写执行以下操作的程序:从任意一组输入中识别2,3和5的倍数,并计算两个最常见的倍数组。 [英] Write a programme that does the following: identifies multiples of 2, 3 and 5 from an arbitrary set of input and computes the two most frequent groups of multiples.

查看:110
本文介绍了编写执行以下操作的程序:从任意一组输入中识别2,3和5的倍数,并计算两个最常见的倍数组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c编程:编写一个程序来识别2,3和3的倍数。 5.到第n个术语并列出2个最常见的frequest最低常见倍数。



我尝试了什么:



void main()

{

int a,b;

int clrscr();

printf(输入两个数字:);

scanf(%d%d,& a,& b);

lcm(a,b);

getch();

//返回0;

}



//计算lcm的函数

void lcm(int a,int b)

{

int m,n;



m = a;

n = b;



而(m!= n)

{

if(m< n)

{

m = m + a;

}

else

{

n = n + b;

}

}



printf(%d的\ nL.CM和%d是:%d,a,b ,m);

}

解决方案

该代码是一个完全不同的任务,它不是前夕n稍微适用于你当前的任务。



我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不打算为你做这一切!


你需要学习C ++ 你的作业。



对于你的任务,你需要有关模运算符%的知识。它的工作方式如下:

  bool  isEven( int  num)
{
if (num% 2 == < span class =code-digit> 0 )
{
cout<< num<< 甚至是;
return true ;
}
返回 false ;
}

您必须检查并计算输入的结果,以获得结果。最好是使用结构来以干净的方式存储数据和结果。



多次检查你编写递归函数或做一些数学运算如

  if (IsEven(num))
{
int num2 = num / 2;
isEven(num2);
}

想一下while循环和一些计数。


拿一张纸和一支铅笔,试一试。



我们不做你的HomeWork。

HomeWork不会测试你乞求别人做你的工作的技巧,它会被设定为您可以考虑并帮助您的老师检查您对所学课程的理解,以及您在应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



[更新]

< blockquote class =quote>

Quote:

我知道如何找到两个或三个数的倍数的LCM。我不知道的是如何获得有问题的数字的重复或常见倍数列表



这不是问题,请仔细阅读你的作业。


c Programming: writing a program to identify the multiples of 2, 3 & 5. upto the n-th terms and lists 2 most frequest Lowest common multiples.

What I have tried:

void main()
{
int a,b;
int clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
lcm(a,b);
getch();
// return 0;
}

//function to calculate l.c.m
void lcm(int a,int b)
{
int m,n;

m=a;
n=b;

while(m!=n)
{
if(m < n)
{
m=m+a;
}
else
{
n=n+b;
}
}

printf("\nL.C.M of %d and %d is: %d",a,b,m);
}

解决方案

That code is a completely different assignment, and it's not even slightly applicable to your current task.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


You need to Learn C++ for your homework.

For your task you need knowledge about the modulo operator %. It works this way:

bool isEven( int num ) 
{
  if( num % 2 == 0 )
  {
    cout << num << " is even ";
    return true;
  }
  return false;
}

You must check and count in someway how it works on your input to get a result. Best is to work with a struct to store the data and the results in a clean way.

To check multiple times you write recursive functions or do some math like

if( IsEven( num ) ) 
{
  int num2 = num/2;
  isEven( num2 );
}

Think about a while loop and some counting.


Take a sheet of paper and a pencil, and give it a try.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

[Update]

Quote:

i know how to find the LCM of the multiples of two or three numbers. what i dont know is how to get a list of the repeated or common multiples of the numbers in question


It is not the question, reread your assignment carefully.


这篇关于编写执行以下操作的程序:从任意一组输入中识别2,3和5的倍数,并计算两个最常见的倍数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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