Monday, 17 October 2016

HHW Q14. WAP to print all the factors of an entered no. and also calculate no. of factors .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c=0,d;
cout<<"Enter the no. ";
cin>>a;
for(int i=1;i<=a;i++)
{ b=a%i;
  if (b==0)
  { cout<<i<<"\n";
    c++;
  }
}
if (c==2)
{cout<<"This is a prime no. ";
}
else
{ cout<<"Nos. of factors = "<<c;
}
getch();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...