Powered By Blogger
Showing posts with label long integer. Show all posts
Showing posts with label long integer. Show all posts

Saturday, December 25, 2010

C Program to find the reverse of a number

/* C Program to print the reverse of a number */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    int num;
    int count=0;
    int ctr;
    int mult=1;
    int result=0;

    printf("Enter the number\n");
    scanf("%d",&num);

    while(num>0)
    {
        mult=1;
        for(ctr=0;ctr<count;ctr++)
        {
            mult=mult*10;
        }
        result=result*mult;
        result=result+(num%10);
        num=num/10;
        count++;
    }

    printf("The Reverse of the given number is %d",result);
    return 0;
}

C Program to find the sum of individual digitis of a number till the sum becomes a single digit

/* C Program to find the sum of individual digits of a long integer until the sum becomes
a single digit */

#include <stdio.h>
int main()
{
    long number;
    int sum=0;
    int digit;

    printf("Enter the number\n");
    scanf("%ld",&number);

    while(number>0)
    {
        sum=0;
        while(number>0)
        {
            digit=number%10;
            number=number/10;
            sum=sum+digit;
        }
        if(sum>9)
        {
            number=sum;
        }
    }

    printf("The sum is %d",sum);

    return 0;
}


Friday, December 24, 2010

C Program to find the number of digits in a long number

/* C Program to find the number of digits in a given long integer number */

#include <stdio.h>

int main()
{
    long num;
    int count=0;

    printf("Enter the number\n");
    scanf("%ld",&num);

    while(num>0)
    {
        num=num/10;
        count++;
    }

    printf("The number of digits in the give number is %d",count);

    return 0;
}

C Program to find the sum of all digits in a number

/* C Program to find the sum of all digits in a given long number accepted from the user */

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long number;
    int sum=0;
    printf("Enter a long number\n");
    scanf("%ld",&number);

    while(number>0)
    {
        sum=sum+(number%10);
        number=number/10;
    }
    printf("The sum of the digits is %d",sum);
    return 0;
}