"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain
Showing posts with label Iteration (unique product components). Show all posts
Showing posts with label Iteration (unique product components). Show all posts

Wednesday, February 24, 2010

WAP to print the product components of a number without repeating them.

eg.  No? 24
output :
24 * 1
12 * 2
8*3
4*6

#include<iostream.h>
#include<conio.h>
void main()
{
int n, s = 1;

cout<<"\n Enter the number to calculate it's product component:";
cin>>n;

clrscr();

cout<<"\n The product Components of "<< n << " is\n";

for(int i = n; i> = s ; i--)
for(int j = 1; j<=n; j++)
{
if(i*j == n)
{
cout<< i << "*" << j << endl;
s = j+1;
}
}


getch();
}

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.