1. Question:Count the number of digits in c programming language 

    Answer
    #include<stdio.h>
    int main(){
      int num,count=0;
    
      printf("Enter a number: ");
      scanf("%d",&num);
    
      while(num){
          num=num/10;
          count++;
      }
      printf("Total digits is:  %d",count);
      return 0;
    }
    Sample output: Enter a number: 23 Total digits is: 2






    1. Report
  2. Question:C code to count the total number of digit using for loop 

    Answer
    #include<stdio.h>
    int main(){
      int num,count=0;
    
      printf("Enter a number: ");
      scanf("%d",&num);
    
      for(;num!=0;num=num/10)
          count++;
    
      printf("Total digits is:  %d",count);
    
      return 0;
    }
    Sample output: Enter a number: 456 Total digits is: 3






    1. Report
  3. Question:Count the digits of a given number in c language using recursion 

    Answer
    #include<stdio.h>
    
    int countDigits(num);
    int main(){
      int num,count;
    
      printf("Enter a number: ");
      scanf("%d",&num);
    
      count = countDigits(num);
    
      printf("Total digits is:  %d",count);
      return 0;
    }
    
    int countDigits(int num){
        static int count=0;
    
         if(num!=0){
              count++;
             countDigits(num/10);
        }
    
        return count;
    }
    Sample output: Enter a number: 1234567 Total digits is: 7






    1. Report
  4. Question:LCM program in c with two numbers 

    Answer
    #include<stdio.h>
    int main(){
      int n1,n2,x,y;
      printf("\nEnter two numbers:");
      scanf("%d %d",&n1,&n2);
      x=n1,y=n2;
      while(n1!=n2){
          if(n1>n2)
               n1=n1-n2;
          else
          n2=n2-n1;
      }
      printf("L.C.M=%d",x*y/n1);
      return 0;
    }
    Alternate Solution:
    #include<stdio.h>
    
    int lcm(int,int);
    
    int main(){
        int a,b,l;
    
        printf("Enter any two positive integers ");
        scanf("%d%d",&a,&b);
     
        if(a>b)
             l = lcm(a,b);
        else
             l = lcm(b,a);
       
        printf("LCM of two integers is %d",l);
    
        return 0;
    }
    
    int lcm(int a,int b){
      
        int temp = a;
    
        while(1){
             if(temp % b == 0 && temp % a == 0)
                 break;
             temp++;
        }
    
       return temp;
    }






    1. Report
  5. Question:LCM program in c with multiple numbers 

    Answer
    #include<stdio.h>
    
    int lcm(int,int);
    
    int main(){
    
       
        int a,b=1;
        printf("Enter positive integers. To quit press zero.");
    
        while(1){
             scanf("%d",&a);
             if(a<1)
                 break;
             else if(a>b)
                 b = lcm(a,b);
             else
                 b = lcm(b,a);
        }
    
        printf("LCM is %d",b);
    
        return 0;
    }
    
    int lcm(int a,int b){
     
        int temp = a;
    
        while(1){
             if(temp % b == 0 && temp % a == 0)
                 break;
             temp++;
        }
    
        return temp;
    }






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd