[ create a new paste ] login | about

Link: http://codepad.org/Eto9SolM    [ raw code | output | fork | 2 comments ]

C, pasted on Aug 18:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	long P;
	do
	{
	printf("\nNhap n(n > 0): ");
	scanf("%d", &n);
	  if(n <= 0)
	   {
		printf("\n N phai > 0. Xin nhap lai !");
	   }
	}while(n <= 0);
    i = 1;
	P = 1;
	while(i <= n)
	{
		if(n % i == 0)
		{
		   printf("%4d", i);
		   P = P * i;
		}
			i++;
	}
	printf("\nTich cac uoc cua %d la: %ld", n, P);
	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by LeHoangAn on Aug 29
#include <iostream>
using namespace std;

int main()
{
int a;
do {
cin >> a;
if (a <= 0) {
cout << " A phai la so nguyen duong";
}
} while (a <= 0);
int S = 1;
int b = 1;
while (b <= a) {
if (a % b == 0) {
S *= b;
}
b++;
}
cout << S;
return 0;
}

reply
posted by tranhieu on Dec 8
#include <iostream>
using namespace std;

int main ()
{
int n;
int mul=1;
cout <<"nhap so nguyen duong N = ";
cin >> n;
cout <<"tich cac uoc cua N la: ";
for (int i = 1;i <= n;i++)
{
if (n % i == 0)
mul *= i;
}
cout << mul<<" ";
return 0;
}
reply