Bài tập 46: Hãy đếm số lượng chữ số lẻ của số nguyên dương n

Bài tập 46: Hãy đếm số lượng chữ số lẻ của số nguyên dương n

Bài tập 46 (Dạng bài tập này giúp các bạn giỏi về: Lưu đồ thuật toán)

Hãy đếm số lượng chữ số lẻ của số nguyên dương n

Cài đặt

#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;
}
Bạn thấy bài viết này như thế nào?: 
Average: 9.3 (4 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Theo dõi đơn hàng trong Drupal Commerce với Google Analytics

Theo dõi đơn hàng trong Drupal Commerce với Google Analytics

Knowing what your customers are doing before spending money in your Drupal Commerce store can be valuable information for your business.

Tổng hợp các biểu tượng hay trên facebook

Tổng hợp các biểu tượng hay trên facebook

Mặt vui, Nhảy múa - Ca hát,...

Thêm kinh nghiệm làm Drupal Project vào LinkedIn

Thêm kinh nghiệm làm Drupal Project vào LinkedIn

Maintaining modules, patching bugs, organizing camps and responding to issues in the issue queue can be a lot of work, and now, you can get professional recognition on LinkedIn for your efforts.

Công ty diệt chuột T&C

 

Diet con trung