hello sir,is there any function in C that can calculate number
of digits in an int type variable,suppose:int a=123;
3 digits in a.what ll b answer?
Answers were Sorted based on User's Feedback
Answer / muni
I am sorry the previous answer is for different question.
For your question the answer is ver simple.
use sprintf and strlen.
char str[10];
sprintf(str,"%d",number)
number of digits = strlen(str);
| Is This Answer Correct ? | 10 Yes | 1 No |
Answer / ramesh
int countDigits(number)
{
if (number==0)
return 0;
else
return 1 + countDigits(number%10);
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / devendra
Answer #2 is right we can also use atoi() and itoa() function.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / arti sharma
void main()
{ int num,i,count=0;
printf("enter a no");
scanf("%d",&num);
while(num!=0)
{ count=count+1;
i=num%10;
num=num/10;
}
printf("count=%d",count);
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sreejesh1987
Small change to Ramesh's answer.
I got answer when i done like this.
int countDigits(number)
{
if (number==0)
return 0;
else
return 1 + countDigits(number/10);//change % to /
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / muni
There is no function to calculate the number of bits. But
there is a very simple logic for calculating it.
int count = 0;
While( num!=0 )
{
count++;
num = num & (num-1);
}
| Is This Answer Correct ? | 1 Yes | 9 No |
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.
2 Answers Mentor Graphics, Microsoft,
Program to Delete an element from a doubly linked list.
4 Answers College School Exams Tests, Infosys,
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
main() { char a[4]="HELL"; printf("%s",a); }
hello sir,is there any function in C that can calculate number of digits in an int type variable,suppose:int a=123; 3 digits in a.what ll b answer?
can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail
x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }
All the combinations of prime numbers whose sum gives 32
Develop a routine to reflect an object about an arbitrarily selected plane