Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
}
Posted
Updated 30-Apr-18 3:16am
Comments
Patrice T 27-Apr-18 4:18am    
What is the problem ?
This code is for another assignment.
Patrice T 27-Apr-18 4:23am    
What is the problem ?
This code is the correct answer for another assignment.
CP is lagged today.

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!
 
Share this answer
 
Comments
Member 13800959 27-Apr-18 5:46am    
m a beginner m not looking for the complete solution m looking for ideas... 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
OriginalGriff 27-Apr-18 5:50am    
So don't post up irrelevant code and expect us to think "Oh, I'll finish that for him" - it's not going to happen.

If you are stuck on a particular point, then show us what you have dones so far, explain where you are stuck, and tell us what help you need.
Member 13800959 27-Apr-18 8:15am    
thanks for the advise.
You need to Learn C++ for your homework.

For your task you need knowledge about the modulo operator %. It works this way:
C++
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
C++
if( IsEven( num ) ) 
{
  int num2 = num/2;
  isEven( num2 );
}
Think about a while loop and some counting.
 
Share this answer
 
v2
Comments
Member 13800959 27-Apr-18 5:47am    
thanks... let me try that
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.
 
Share this answer
 
v2
Comments
Member 13800959 27-Apr-18 5:47am    
m a beginner m not looking for the complete solution m looking for ideas... 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
Patrice T 27-Apr-18 6:11am    
Then say it, reread your question, how are we supposed to understand what you just said ?
Use Improve question to update your question.
You say you are new to programming.

What made you take the course? Is is because you liked it (but you're new, so that can't be it) or you think it will get you a great job (only if your competent)?

If someone just told you "it's the best field to go into for work or money" or something, just remember: they room's full of people just like you - so, by the time you graduate you won't be in any kind of high demand. Crappy pay. Crappy work. Little or no respect.

Some things, despite the common myth of applying yourself, are beyond the reach of most people. At this early stage, evaluate your limitations. Your strengths and weaknesses.

And remember - what you do may be for the rest of your life. Money is nice, but it doesn't compensate for drudgery and misery.
 
Share this answer
 
Comments
Member 13800959 27-Apr-18 8:25am    
i have always wanted to be a programmer. m a banker by profession but i have been working for a Private Company as an IT Technician for 7 years in counting. So i got into school this last year and m just trying to develop my skills.
W Balboos, GHB 27-Apr-18 8:34am    
When I think about it, I don't actually know what a 'banker' is, except for someone who works in a bank in some way.

But - you've been an IT Tech for seven years and started school in this last year. You really don't qualify as 'new' to the point that your question's quality implies.

Where I am, there are IT techs - keeping everything running. They do not (and generally, can not) write code. They set things up and fix things. Some help users. The very clever ones even have access to account maintenance. But they don't code.

That's OK - but the question, after all these years, is what are you looking for? The way to code is to attack the question with all your resources - look things up (and thus learn them) - particularly, the basic operators for our language of choice. 'C', by the way, is not an easy starting point. How did you come to select a course in 'C'?
Member 13800959 27-Apr-18 9:08am    
i love to learn new things. Before i studied banking and finance i enrolled for computer science and software engineering thats what i really wanted to do. but i couldn't then due to certain reasons. so banking was just my way of getting started. i dont need to be taught everything. i cant code right now but m able to learn any system in and out without stressing & discover its pros and cons.
#include<conio.h>
void main()

{
int n1,n2,n3,n4,n5,n6;
int a,b,c,l,g,p,i;
int clrscr();
int q=1,ct=1,sum=0,n;

n1=1;
n2=100;
n3=1;
n4=120;
n5=1;
n6=100;

printf("Enter Three Integers and the upper Limit: \n"); /*ENTER THE THREE NUMBERS YOU WANT TO CALCULATE LCM AND THE UPPER LIMIT AT THE END*/
scanf("%d%d%d%d",&a,&b,&c,&n);
i=1;
 while(i<=a)
 {
 if(a%i==0&&b%i==0&&c%i==0)
 g=i;
 i++;
 }
 i=1;
 p=a*b*c;
  while(c<=p)
     {
     if(i%a==0&&i%b==0&&i%c==0)
     {
     l=i;
     break;
     }
     i++;
     }
      printf("\n");

while(n1<=n2)
{
if(n1%a==0)
printf("%d\t",n1);
n1=n1+1;
}
while(n3<=n4)
{
if(n3%b==0)
printf("%d\t",n3);
n3=n3+1;

}
while(n5<=n6)
{
if(n5%c==0)
printf("%d\t",n5);
n5=n5+1;

}
printf("\nWith Upper Limit of 100, The Two Most frequent multiples of %d, %d & %d are(is)...\n",a,b,c);
   while(q<=n)
    {
    if(q%a==0 && q%b==0 && q%c==0 )
     {
     printf("%d\t",q);
     ct++;
     sum=sum+q;
     }
    q++;
    }

    printf("\ncount=%d",ct);


getch();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900