[ create a new paste ] login | about

Link: http://codepad.org/eJl1V3uh    [ raw code | output | fork | 9 comments ]

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

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

	if(n == 0)
			sochuso = 1;
	while(themang != 0)
	{
		sochuso = sochuso + 1;
		themang = themang / 10;
	}
	printf("\nSo chu so cua %ld la %d", n, sochuso);

	//int sochuso = n == 0 ? 1 : (int)log10((float)n) + 1;

	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 LamNT on Sep 28
vì sao themang = themang / 10 ạ?
mình không hiểu lắm bạn có thể cho mình biết kĩ hơn được không ạ?
reply
posted by mouto9k on Nov 15
vidu so 26
lan 1: 26/10=2 (1 chu so)
lan 2: 2/10=0 (1 chu so)
do 0!=0 sai nen vong lap dung lai
reply
posted by freshman27 on Apr 15
Hữu ích quá!

reply
posted by nguyentuan250298 on Mar 4
#include<stdio.h>
#include<conio.h>
int main()
{
int temp,n;
int sochuso;

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

if(n == 0)
printf("khong co so le nao");
while(n != 0)
{
temp=n%10;
n=n/10;
if(temp%2==1)
sochuso=sochuso+1;
}
printf("%d",sochuso);

getch();
}
theo mình thấy bài gốc không hợp lí. bài của mình đây. mọi người góp ý nhé
reply
posted by nguyentuan250298 on Mar 4
chết cha. mk rep nhầm bài rồi.
reply
posted by dangtiendat86@gmail.com on Feb 5
#include<iostream>
using namespace std;
int DemCS(int n){
int d=0;
while (n!=0){
n/=10;
d++;
}
return d;
}
main(){
int n;
cout<<"n="; cin>>n;
while (n<1){
cout<<"Nhap lai n="; cin>>n;
}
cout<<"kq="<<DemCS(n)<<endl;
}

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 sum = 0;
while(n != 0){
n=n/10;
sum++;
}
cout<<sum<<
endl;
return 0;
}
reply
posted by 20223768 on Sep 12
#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
int count=1;
while (n>=10)
{
n=n/10;
count ++;
}
cout << count;
return 0;
}
reply
posted by 20223768 on Sep 12

reply