Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

WACHEMO UNIVERSITY

COLLEGE OF ENGINEERING
AND TECHNOLOGY
Computer programming course
Individual Assignment for pre-engineering section 'G'
Name Iyasu Taressa
Id number 4231
1. Write a c++ program that takes a number from the user and prints factors of the
number?
Answer
/*this is a c++ program that takes a numbers from users
and print factors of the number*/
#include<iostream>
using namespace std;
int main()
{
int n;//local variable decelerations
cout<<"Enter a number ";
cin>>n;//take input
cout<<"Factor of "<<n<<" are :";
for(int i=1; i<=n; i++) //for loop execution
{
if(n%i==0) // if the condition is true print the following
cout<<i<<",";
}
return 0;
}
2. Write a c++ program that takes a number and a limit and prints multiples of
a number upto the limit.
Answer
/*this is a c++ program that takes a numbers and a limit
and gives the multiples of the number up to limits*/
#include<iostream>
using namespace std;
int main()
{
int x,y;
long long int product=1;//local variable decelerations
cout<<"Enter a number ";
cin>>x;//take input
cout<<"Enter the limit ";
cin>>y;//take input
for(int i=x; i<=y; i++) //for loop execution
{

product=product*i;

}
cout<<"multiples of "<<x<< " up to "<<y<<" is "<<product;
return 0;
}

You might also like