[ create a new paste ] login | about

Link: http://codepad.org/kIsrIcF3    [ raw code | output | fork | 1 comment ]

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

int main()
{
	int i, n;
	long S;
	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;
	S = 0;
	printf("\nCac uoc nho hon %d la",n);
	while(i < n)
	{
		if(n % i == 0)
		{
			printf("%4d", i);
		   S = S + i;
		}
			i++;
	}
	printf("\nTong cac uoc nho hon %d la: %ld", n, S);
	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 hai on Dec 25
#include<iostream>
#include<cmath>
using namespace std;
int main() {
float S = 1, P = 0;
int n, i = 1, a = 0, dem = 0; //khai sẵn trước để dùng cho các bài sau luôn
do
{
cout << "\nnhap so n : ";
cin >> n;
if (n < 1)
{
cout << "\nso nhap kh dung vui long nhap lai";
}
} while (n < 1);
for (i = 1; i < n; i++)
{
if (n % i == 0)
{
P = P + i;
}
}
cout << "\ntong cac uoc so nho hon n cua n : " << P << endl;
return 0;
}
reply