#include
#include
void main()
{
unsigned long int num;
int i=0;
clrscr();
printf("Enter the digit\n");
scanf("%lu",&num);
while(num!=0)
{
num=num/10;
++i;
}
printf("Length=%d",i);
getch();
}
There are two ways. The naive way is to convert the number to a string by inserting it into a stringstream object and returning the size of the resultant string. A more efficient method is to repeatedly divide the number by 10 until the result is zero. The number of divisions gives the count of digits.
#include<stdio.h>
unsigned count_digits (unsigned num) {
unsigned sum;
sum = 1;
while (num /= 10) ++sum;
return sum;
}
int main (void ) {
unsigned num;
printf ("Enter a positive integer: ");
scanf ("%d", num);
printf ("There are %d digits in the number %d\n", count_digits (num), num);
return 0;
}
I suggest to convert it to a String, then use the String method to count the number of characters.
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
x -=y;
Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.
title bar
How to write a program for mouse in microprocessor?
see the program
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
Which microprocessor accepts the program written for 8086 without any changes?
Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.
x -=y;
youtube
ten
1 hour ago my c program said no, but now I know 5 actually is an integer!
title bar
A screen (VDU).
gfgyhgcfh
Write a program which displays digital watch on the screen, after taking the hours and minutes from the user.