1. Write a c program to reverse any number.

2. Write a c program to find out sum of digit of given number.

2. Write a c program to find out sum of digit of given number.

10. Write a c program to find out NCR factor of given number.

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

## 35 comments:

THANK YOU SOOOOOO MUCH

AMAZING

great

ITS VERY USEFUL

much thanks for helping people like us to learn c program logic...may ur service for education continue

hehehehe..............:-))

nyc one

very useful

Thank you so much.... It helps me alot

hi

did u tried with the number having digits more then 10,it is giving some junk value

let alone two succinct calls of the recursive one. lame!

Thanks for your time.

thousand of thanks admin

thanks alot

print 1-100.....without loop...how to print?

#include

main()

{

static int i=1;

if((printf("%d\n",i++))&& i<=100)

main();

}

wid the help of recursion..

but this progarm run to count only 10 digit after that what should we do

but this program will not count 0 which is also a digit.

for example 123=3

43078=5

0=1

we count digits

0 is also a number

So Correct ur program.

hi Anand Barnwal you used main(); inside if condition i dint get can u explain it.. thanks

here main() is called....in main function.....recursively...untill i>100 :)

thankx a lot i think it will help me a lot. thanx again

There is much faster way which has complexity about (log(log10(n)))^2

For large numbers like 10^1000, you would need 1000 operations for all previous codes, with the code below around 50.

It is basically a binary search over the exponent of 10 in binary form. For example for 10^27 we search 1-2-4-8-16-32, then 1-2-4-8-16, then 1-2-4, then 1-2, and that is 16 guesses.

For small numbers you might not see any benefits, but already for 10^32, instead of 32, you have only 8 operations.

#include

int main(){

int n;

printf("Enter a number: ");

scanf("%d",&n);

int r = 10;

int d = 1;

int t = 0;

int p = r;

int dig=1;

while(1)

{

while (1)

{

if (n < t+r) break;

p = r;

r = r*r;

d = 2*d;

}

if (d==1) break;

dig += d/2;

n = n/p;

d = 1;

t = 0;

p = r = 10;

}

printf("Total digits is: %d\n", dig);

return 0;

}

The following solution is even faster, although it needs log2(log10(n)) additional space because it uses recursion. It needs only log2(log10(n)) calls. It is basically a wrapped binary decomposition of exponent of 10.

void nextLevel(int* n, int r, int* dig, int d)

{

int t=r;

r=r*r;

if(*n>=r)

{

d = 2 * d;

nextLevel(n,r,dig,d);

if(*n>=r)

{

*n=*n/r;

*dig += d;

}

}

}

main()

{

int n;

printf("Enter a number: ");

scanf("%d",&n);

int r = 10;

int dig = 1;

int d = 1;

nextLevel(&n, r, &dig, d);

if(n>=10) dig++;

printf("%d", dig );

}

This line int t=r; is not needed

thanks

Write down the definition of a function count2s which takes a number as argument and returns the count of the digit 2 in it?

Your program to calculate the no of digits in an integer is incorrect.

As an example try 20000.

need count the digits of a given number using do while & while loop

*

* *

* * *

* *

*

i want this program.plz help me

1. int calculateOccurrenceOfDigit(int number, int digit);

Complete the above prototyped function that will return total number of occurrence of digit in a number. For e.g. calculateOccurrenceOfDigit( 102015400, 0) will return 4 as it has 4 zeros.

You have to use recursion.

int calculateOccurrenceOfDigit(int number, int digit)

{

.............. i need the answer

but it won t work if number have more than 10 digits

Nicely Done.!

<it's really super>

In this program have one mistake..that is (int num) 0 cannot be read the compiler,so using (long int num) the program will correctly executed in more than digits..

Fun

Post a Comment