I wanted to write a program that finds the factor of a no. eg 2 and 5 are factors of 10. But that program is not working .Please tell me what is wrong with my program.Also tell me how to finally write like "10=2*5". Despite having learned functions and arrays i don;t seem to be able to put them to use. Please help me.
#include<iostream>
using namespace std;
int function (int a, int b);
int main ()
{
cout<<"This program finds the factor of a no."<<endl;
int a,b;
cout<<"Please input a no."<<endl;
cin>>a;
cout<< b <<"is a factor of " << a<<endl;
return 0;
}
int function ( int a,int b)
{
for(b=0;b>1&& b<32;b++)
{
if (a%b==0)
return b;
}
return 0;
}
Jack_1 0 Newbie Poster
thelamb 163 Posting Pro in Training
amrith92 119 Junior Poster
Anilyargunta 0 Newbie Poster
maryam ahmad 0 Newbie Poster
NP-complete 42 Junior Poster
amrith92 119 Junior Poster
NP-complete 42 Junior Poster
amrith92 119 Junior Poster
NP-complete 42 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.