[ create a new paste ] login | about

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

C, pasted on Aug 21:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	long themang, n;
	int sochuso;
	float S = 0;
	do
	{
	printf("\nNhap n: ");
	scanf("%ld", &n);
	}while(n < 0 && printf("\nLoi: n >= 0 !"));
	sochuso = 0;
	themang = n;

	while(themang != 0)
	{
		if(themang % 2 == 0)
		{
		S = S + themang % 10;
		}
		themang = themang / 10;
	}
	printf("\nTong cac chu so chan cua %ld la %f", 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 yonnon on Jul 7
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
cout <<"Enter your sentence: ";
cin >> n;
int temp =0;
int sum =0;
while( n!= 0){
temp = n%10;
if(temp %2 ==0){
sum+=temp;
}
n /=10;
}
cout<<sum<<
endl;
return 0;
}
reply
posted by tranngocthe111 on Oct 13
#include <iostream>
using namespace std;
int main() {
int n;
long s;

long sotachra;
s = 0;
do {
cout << "hay nhap so nguyen n :\n";
cin >> n;
if (n <= 0)
cout << "hay nhap lai so n >0:\n";
} while (n <= 0);
while (n != 0) {
sotachra=n%10;
n=n/10;
if (sotachra % 2 == 0)
s += sotachra;

}
cout << "tong so chan cua so n la :\n" << s << endl;
return 0;
}


reply