[ create a new paste ] login | about

Link: http://codepad.org/Ql68PK00    [ raw code | output | fork | 4 comments ]

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;
	while(i <= n)
	{
		if(n % i == 0)
		{
			printf("%4d", i);
		   S = S + i;
		}
			i++;
	}
	printf("\nTong cac uoc cua %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 cuong.luucb8921 on Aug 18
#include<stdio.h>

int main(){
int i;
int n;
int sum = 0;
do
{
printf("Nhap vap n:\n");
scanf("%d",&n);
if(n < 1)
{
printf("n phai lon hon bang 1\n");
}
}while(n < 1);

for(i=1;i<=n;i++)
{
if(n%i==0)
{
sum = sum + i;
}
}

printf("Tong bang %d",sum);
return 0;
}

reply
posted by cuong.luucb8921 on Aug 18
#include<stdio.h>

int main(){
int i;
int n;
int sum = 0;
do
{
printf("Nhap vap n:\n");
scanf("%d",&n);
if(n < 1)
{
printf("n phai lon hon bang 1\n");
}
}while(n < 1);

for(i=1;i<=n;i++)
{
if(n%i==0)
{
sum = sum + i;
}
}

printf("Tong bang %d",sum);
return 0;
}

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

int main() {
int a;
int S = 0;
do {
cin >> a;
if (a <= 0) {
cout << "a phai la so nguyen duong";
}
} while(a <= 0);
int b = 1;
while (b <= a) {
if (a % b == 0) {
S = S + b;
}
b++;
}
cout << S;
return 0;
}
reply
posted by luongphongnhan on Oct 17
#include<iostream>
using namespace std;

int main() {
int i = 1;
long s = 0;
int n;
do
{
cout << "Moi nhap n: ";
cin >> n;
if (n <= 0) {
cout << "n phai lon hon 0!" << endl;
}
} while (n<=0);

do
{
if (n % i == 0) {
s += i;
}
i++;
} while (n>=i);
cout << "tong giai thua cua " << n << " la " << s << endl;
system("pause");
return 0;
}
reply