[ create a new paste ] login | about

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

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

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

	while(themang != 0)
	{
		P = P * (themang % 10);
		themang = themang / 10;
	}
	printf("\nTich la %d", 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 kawasakikute123@gmail.com on Oct 25
Cho em hỏi nếu nhập n = 0 thì ra tích = 1 là sao ạ?

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 tich =1;
int temp =0;
while( n!= 0){
temp = n%10;
tich = tich*temp;
n /= 10;
}
cout<<tich<<
endl;
return 0;
}
reply
posted by luongphongnhan on Oct 21
#include <iostream>
using namespace std;

int tich(int n) {
int tich = 1;
int chuSo;
while (n != 0)
{
chuSo = n % 10;
tich *= chuSo;
n = n / 10;

}
return tich;
}

int main() {
int n;
do
{
cout << "Moi nhap so n: ";
cin >> n;
if (n < 0) {
cout << "so n phai lon hon 0!" << endl;
}

} while (n <=0);
cout << "So chu so cua so " << n << " la " << tich(n) << endl;
system("pause");
return 0;
}
reply
posted by 20223768 on Sep 12
#include <iostream>
using namespace std;
int main()
{
int n; cin >>n ;
int s=1; int t=1;
while (n!=0)
{
s=n%10;
t=t*s;
n=n/10;
}
cout << t;
return 0;
}
reply