C Program to count number using for loop

C  Program to  count number using  for loop   : 


This C program to count digits in a number allows the user to enter any positive integer. And then, it will divide the given number into individual digits and count those individual digits using for loop 


Example :

 Input : 12548

Output : 6


Code : 



#include<stdio.h>
int main()
{
    int n,i;
    int count =0;
    printf("Enter the number : ");
    scanf("%d",&n);
    for(i=0;n!=0;i++){
            count++;
         n=n/10;
    }
    printf(" total number = %d\n",count);
    /// or using
   /// printf("total number = %d",i);
    return 0;
}



Output : 



No comments

Powered by Blogger.