[ create a new paste ] login | about

Link: http://codepad.org/9RHO1DxZ    [ raw code | output | fork | 9 comments ]

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

int main()
{
	int i, n;
	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;

	while(i <= n)
	{
		if(n % i == 0)
			printf("%4d", i);
			i++;
	}

	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 bangtran on Jan 22
// code by bangtran
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
int n, k;
cout << "Nhap so nguyen duong n: " ;
cin >> n;
k = n / 2;
cout << "Cac uoc so cua " << n << "la: ";
for (int i = 1; i <= k; i++)
{
if (n % i == 0)
cout << i << " ";
}

// END MAIN
cout << "\n\n <---Code By bangtran---> \n";
system("pause");
}

reply
posted by chjchjmama2 on Feb 28
nếu bạn sửa lại chỗ vòng lặp for đk i<=n nó sẽ cho ra kết quả chính xác hơn ấy
reply
posted by chjchjmama2 on Feb 28
và chỗ k=n/2 đó bạn cũng bỏ luôn đi nó không cần thiết
reply
posted by kokokouuty on Mar 25
bangtran : uoc chung cua 10 la 1,2,5,10 bạn thiếu ước là chính nó rồi( kq thiếu số 10)

reply
posted by bongrompa@gmail.com on Jun 2
#include "stdio.h"
#include "conio.h"
#include "math.h"
//-----------------------------
void souoc( designed n)
{ for( int i=1;i<=n;i++)
if(n%i==0)
printf("%d",i);
}
//----------------------------
void main()
{ clrscr();
designed n;
printf("\n nhap n: "); scanf("%d",n);
printf("\n cac uoc so la:");
souoc(n);
getch();
}
reply
posted by LeHoangAn on Aug 29
#include <iostream>
using namespace std;

int main() {
int a;
int b;
do {
cin >> a;
if (a <= 0) {
cout << "a phai la so duong";
}
} while (a <= 0);
b = 1;
while (b <= a) {
if (a % b == 0)
cout << b;
b++;
}
return 0;
}
reply
posted by luongphongnhan on Oct 17
#include<iostream>
using namespace std;
void tim_uoc(int a) {
for (int i = 1; i <= a; i++)
{
if ( a % i == 0)
cout << i << " ";
}
}
int main() {
int n;
do
{
cout << "Moi nhap so nguyen n" << endl;
cin >> n;
system("cls");
tim_uoc(n);
cout << endl;
} while (n > 0);
if (n < 0) {
cout << "so can nhap phai lon hon 0;" << endl;
return -1;
}
system("pause");
return 0;
}
reply
posted by tranhieu on Dec 8
#include <iostream>
using namespace std;

int main ()
{
int n;
cout <<"nhap so nguyen duong N = ";
cin >> n;
cout <<"cac uoc chung cua N la: ";
for (int i = 1;i <= n;i++)
{
if (n % i = 0)
cout << i;
}
return 0;
}
reply
posted by tranhieu on Dec 8
cái chỗ kia là n % i == 0 nhé

reply