Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
Susun Program
0
votes
asked
May 24, 2018
by
Yuda
Susun program untuk menginput sebuah nilai integer lebih besar dari nol, yang di terima oleh variabel N bertipe long int, kemudian cetak jumlah digit nilai yang ada dalam N
contoh
Bila di input
5
12
724
141830322
maka tercetak
1
2
3
10
Please
log in
or register to answer this question.
1 Answer
0
votes
answered
May 24, 2018
by
muha
how is the last number 10 when it should be 9?
anyway here is a simple approach:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int x, y;
cout << "Type in a number: ";
cin >> x;
if(x<10 && x > 0){
y = 1;
}
if(x>=10) y = 2;
if(x>=100) y = 3;
if(x>=1000) y = 4;
if(x>=10000) y = 5;
if(x>=100000) y = 6;
if(x>=1000000) y = 7;
if(x>=10000000) y = 8;
if(x>=100000000) y = 9;
if(x>=1000000000) y = 10;
cout << "Number of digits is: " << y;
return 0;
}
commented
May 30, 2018
by
anonymous
I have no idea what the question's language is but this is a terrible way to count digits. Just create a loop that increments a counter while the test value > 0 and divide the number by 10 at the end of every iteration
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...