Basic c program to count number of digits using while loop. Using this program we can count the number of digits in a number in a programming language.
Pre Increment and Post Increment in C
The value is incremented by one before being assigned to the variable with pre-increment. After assigning a value to a variable, the value is incremented using the post-increment method.
++ I’m going to increase the value of I and then return the new value. i++ will increase the value of I but it will also return the value that I had before it was incremented. With the help of pre increment and post increment operator in c programming language we have executed the c program to count number of digits using while loop
While Loop in C Program
In C programming, the while loop is the most fundamental loop. The while loop has only one control condition and runs as long as it is true. An entry-controlled loop is one in which the loop’s condition is evaluated before the loop’s body is run.
C Program to Count Number of Digits Using While Loop
//c program to count number of digits using while loop
#include <stdio.h>
int main()
{
long long n;
int count = 0;
printf("Enter the number");
scanf("%lld", &n);
do
{
n /= 10;
++count;
}
while (n != 0);
printf("Number of digits%d", count);
}
Output:
Enter the number 4566
Number of digits 4
Swapping of Two Numbers in C Without Temporary Variable
C Program to Swap Two Numbers Using Functions
C Program to Swap Two Numbers Using Pointers
C Program to Reverse a Number Using Recursion
Reverse a Number in C Using Function
C Program to Check Vowel or Consonant Using Function
Leap Year Program in C Using Function
Factorial Program in C Using Recursion