[ create a new paste ] login | about

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

C, pasted on Aug 21:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int themang, n;
	int S;

	do
	{
	printf("\nNhap n: ");
	scanf("%d", &n);
	}while(n < 0 && printf("\nLoi: n >= 0 !"));
	S = 0;
	themang = n;

	while(themang != 0)
	{
		S = S + themang % 10;
		themang = themang / 10;
	}
	printf("\nTong la %d", 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 yonnon on Jul 7
#include<iostream>
#include<cstring>

using namespace std;
int main(){
int n;
cout << "Enter your sentence: ";
cin >> n;
int sum =0;
int temp = 0;
while( n != 0 ){
temp = n % 10;
sum += temp;
n = n / 10;

}
cout<<sum<<
endl;
return 0;
}
reply