Monday, September 12, 2011

find number of digits in the given integer

/* To find the no. of digits in the given integer */
#include<stdio.h>
#include<conio.h>
main()
{
    int x,i=0,a[10],k;
    long n;
    clrscr();
    printf("\n enter an integer :");
    scanf("%ld",&n);
    while(n>0)
    {
    x=n%10;
    a[i]=x;
    n=n/10;
    if(a[i]==0)
        break;
    else
        i++;
    }
    printf("\n The number of digits in the given number are:%d",i);
    printf("\n And the numbers are:");
    for(k=i-1;k>=0;k--)
        printf("\n%d",a[k]);

    getch();
    }

Calculate HCF of two numbers

main()
{
    int a,b;
    clrscr();
    printf("\n Enter any two nos.:");
    scanf("%d %d",&a,&b);
    printf("\n HCF of the two nos.:%d",gcd(a,b));
    getch();
}

    gcd(int n,int d)
    {
      int r;
      do{
         r=n%d;
         n=d;
         d=r; }while(r!=0);
      return(n);
      }

Popular 5 Posts Last 7 days