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

THANK YOU SOOOOOO MUCH

ReplyDeleteAMAZING

ReplyDeletegreat

ReplyDeleteITS VERY USEFUL

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

ReplyDeletehehehehe..............:-))

ReplyDeletenyc one

very useful

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

ReplyDeletehi

ReplyDeletedid 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!

ReplyDeleteThanks for your time.

ReplyDeletethousand of thanks admin

ReplyDeletethanks alot

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

ReplyDelete#include

Deletemain()

{

static int i=1;

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

main();

}

wid the help of recursion..

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

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

ReplyDeletefor 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

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

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

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

ReplyDeleteFor 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.

ReplyDeletevoid 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

DeleteThis comment has been removed by the author.

ReplyDeletethanks

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

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

ReplyDeleteAs an example try 20000.

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

ReplyDelete*

ReplyDelete* *

* * *

* *

*

i want this program.plz help me

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

ReplyDeleteComplete 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

ReplyDelete