C/C++: Bài 43 hãy đếm số lượng chữ số của số nguyên dương n

C/C++: Bài 43 hãy đếm số lượng chữ số của số nguyên dương n

Bài tập 43 (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ố 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)
    {
        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;
}
Bạn thấy bài viết này như thế nào?: 
Average: 10 (2 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

 
Hướng dẫn cài đặt LiteSpeed, PHP, MySQL và phpMyAdmin trên Ubuntu/Debian

Hướng dẫn cài đặt LiteSpeed, PHP, MySQL và phpMyAdmin trên Ubuntu/Debian

Bài viết sẽ hướng dẫn các bạn cài đặt LiteSpeed và MySQL cùng với việc xây dựng PHP tùy biến, và phpMyAdmin để quản lí database trên MySQL trên hệ điều hành họ Ubuntu/Debian một cách đầy đủ.

Phần 1: Hướng dẫn Data Migration từ HTML Pages vào Drupal 7

Phần 1: Hướng dẫn Data Migration từ HTML Pages vào Drupal 7

I recently was faced with a project where the client has a "database" of items that will be brought into the brand new Drupal 7 site that we are preparing for him.

Embarking

Giới thiệu Embarking on a Drupal 8 adventure

We know Drupal 7 pretty well, we know what it can do but we also know what its limitations are.

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

 

Diet con trung