[ create a new paste ] login | about

Link: http://codepad.org/YsDrc1Wk    [ raw code | output | fork | 5 comments ]

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

	while(themang != 0)
	{
		if(themang % 2 == 1)
		{
		 P = P * (themang % 10);
		}
		themang = themang / 10;
	}
	printf("\nTich cac chu so le cua %ld la %d", n, P);

	

	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 manhha on Feb 10
// Hãy tính tích các chữ số lẻ của số nguyên dương n
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
long themang, n;
int S;
do
{

printf("Nhap vao n = \n", n);
scanf("%d", &n);
if (n % 2 == 1)
{
S = 1;
}
else
{
S = 0;
}

} while (n < 0 && printf("n >= 1, xin nhap lai!", n));

themang = n;

while (themang != 0)
{

if (themang % 2 == 1)
{
S = S * (themang%10);
}
themang = themang / 10;
}
printf("Tich cac chu so le cua so nguyen %ld la %d", n, S);

getch();
return 0;

}
reply
posted by manhha on Feb 10
// Hãy tính tích các chữ số lẻ của số nguyên dương n
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
long themang, n;
int T = 1;
do
{

printf("Nhap vao n = \n", n);
scanf("%d", &n);

} while (n < 0 && printf("n >= 1, xin nhap lai!", n));

themang = n;

while (themang != 0)
{

if (themang % 2 == 1)
{
T = T * (themang%10);
}
themang = themang / 10;
}
if (T == 1)
{
printf("Khong co so le nao.\n");
}else
{
printf("Tich cac chu so le cua so nguyen %ld la %d", n, T);
}

getch();
return 0;

}
reply
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 tich = 1;
while(n != 0){
temp = n% 10;
if (temp % 2 != 0 ){
tich *= temp;
}
n/=10;
}
cout<<tich<<
endl;
return 0;
}
reply
posted by cuong.luucb8921 on Aug 21
#include<stdio.h>

int main(){
int n;
int t;
int s;
int tich=1;

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

t = n;
while(t!=0)
{
s = t%10;
t = t/10;
if(s%2==1)
{
tich = tich*s;
}
}
printf("Tich cac chu so le cua %d la %d",n,tich);
return 0;
}
reply
posted by tranngocthe111 on Oct 13
#include <iostream>
using namespace std;

int main() {
int n;
long p;
long tachSo;
do{
cout<<"nhap n :\n";
cin>>n;
if(n<=0){
cout<<"nhap lai so nguyen n>0:\n";}
}while(n<=0);
p=1;
while(n!=0){
tachSo=n%10;
n/=10;
if(tachSo%2==1)
p=p*tachSo;
}
cout<<"ket qua tich cac chu so nguyen le:\n "<<p<<endl;

return 0;
}


reply