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)
{
if(themang % 2 == 1)
{
sochuso = sochuso + 1;
}
themang = themang / 10;
}
printf("\nSo chu so le cua %ld la %d", n, sochuso);
//int sochuso = n == 0 ? 1 : (int)log10((float)n) + 1;
getch();
return 0;
}
|
Output:
|
Line 17: error: conio.h: No such file or directory
|
|
Create a new paste based on this one
Comments:
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
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++;
}
n/=10;
}
cout<<sum<<
endl;
return 0;
}
reply
posted by
cuong.luucb8921
on Aug 20
#include<stdio.h>
int main(){
int n;
int t;
int s;
int sochuso=0;
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)
{
sochuso = sochuso + 1;
}
}
printf("So chu so cua %d la %d", n, sochuso);
return 0;
}
reply
posted by
tranngocthe111
on Oct 13
#include <iostream>
using namespace std;
int main() {
int n, dem;
int sotachra;
dem = 0;
do {
cout << "hay nhap so nguyen n : \n";
cin >> n;
if (n <= 0)
cout << "hay nhap la so nguyen n:\n";
} while (n <= 0);
while (n != 0) {
sotachra = n % 10;
if (n % 2 == 1)
n/=10;
dem++;
}
cout<<"chu so le :"<<dem;
return 0;
}
reply
posted by
20223768
on Sep 12
#include <iostream>
using namespace std;
int main()
{
int n; cin >>n;
int s=1;
int count =0;
while (n!=0)
{
s=n%10;
if (s%2!=0) count++;
n=n/10;
}
cout << count;
return 0;
}
reply