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

 
Book: Selling Online with Drupal e-Commerce

Download sách Drupal: Selling Online and Drupal e-Commerce

Drupal is a free and open-source modular web application framework and content management system (CMS) written in PHP that can run in many environments, including Windows, Mac OS X, Linux, and FreeBSD. Drupal e-Commerce is a free, open-source, feature-rich, flexible package of modules that seamlessly adds full e-Store capabilities to Drupal.

Cách tạo một trang Calendars trong Drupal 7

Cách tạo một trang Calendars trong Drupal 7

We're going to show you how to create an event calendar in Drupal. This tutorial is ideal for people who want to show a monthly, weekly or daily list of upcoming events.

Alexa

Biện pháp tăng Alexa Rank

Thủ thuật tăng thứ hạng Alexa rất đa dạng. Nhưng về cơ bản Website của bạn cần thiết phải thực hiện những điều đơn giản sau để các cralwer của Alexa chú ý đến website của bạn hơn

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

 

Diet con trung