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

 
Khóa học Drupal 60 ngày từ số zero với Acquia Lightning

Khóa học Drupal 60 ngày từ số zero với Acquia Lightning

To build great sites and digital experiences, you need easy-to-use tools for rapid development, simple page building, drag-and-drop widgets for rich media and content

dien thoai di dong

Sử dụng chung di động có thể lây lan bệnh truyền nhiễm

ĐTDĐ có lượng vi khuẩn lớn gấp 10 lần so với một chiếc toilet, vì vậy không có gì ngạc nhiên khi một người đàn ông Uganda đã chết vì nhiễm vi khuẩn Ebola sau khi ăn cắp một chiếc ĐTDĐ từ phòng cách li của bệnh viện tại địa phương nơi đã bùng phát dịch bệnh do khuẩn Ebola.

The Best Video Player On Android–MoboPlayer

The Best Video Player On Android–MoboPlayer

MoboPlayer is the alternative video player to the default Android player. It is definitely the one app that will replace stock music application that you have been having on your Android phone.

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

 

Diet con trung