# digit « Development « C Data Type Q&A

Home
C Data Type Q&A
 1 binary 2 bit 3 byte 4 char 5 character 6 decimal 7 Development 8 float 9 hex 10 integer 11 prime 12 random 13 struct
 C Data Type Q&A » Development » digit

### 1. how to display all the distinct 7-digit number among 2 to 9?    stackoverflow.com

what i mean is all the numbers _ _ _ _ _ _ _ are distinct and only values 2 to 9 can be entered. I've tried using array and loops ...

### 2. C - need to detect presence of digit in a number (hw)    stackoverflow.com

I'm trying to write a function that'll detect if a digit is found in a number:

``````// returns 1 if source contains num, 0 otherwise
int contains_num(source, num);
``````
for example, contains_num(12345, 3) returns 1 ...

### 3. checking every digit in a number for oddness    stackoverflow.com

I was writing a function which checks if every digit in a number is odd. I came accross this weird behaviour. Why does the second function return different (incorrect) results, eventhough ...

### 4. How to determine if the number has identical digits in C    stackoverflow.com

Efficient way to determine if the number has identical digits in C

### 5. How to use 12 digit number in C?    stackoverflow.com

I am dealing with a math example. I need to use 12 digit number for my code. So which datatype should i use, to use the number in my functions?

### 6. C write number digits, one by one and in extension, in a new line    stackoverflow.com

I'm new in C and I can't do a simple exercise for school. I want to do something like this:

`````` Please insert a number: 12345
five
four
three
two
one
``````
Basically, the user ...

### 7. How to create a datatype to hold 200+ digit long numbers in C?    stackoverflow.com

OK,so I am trying to solve this problem: http://www.spoj.pl/problems/FCTRL2/ And using what I know about c, I have come up with this code:

``````#include <stdio.h>
#include <conio.h>
long double factorial(int);
int main()
{
...``````

### 8. Finding out the first and the last digit of any number    stackoverflow.com

C program to find the first and last digit of a number. suppose i had given a number 158436, o/p should be 1,6

### 9. Program to add digits of a number    stackoverflow.com

This is a program to a 5 digit number from user and output the sum of digits. The program works for some numbers. See the output image. Why is the program ...

### 10. How can I iterate through each digit in a 3 digit number in C?    stackoverflow.com

Length is always 3, examples:

``````000
056
999
``````
How can I get the number so I can use the value of the single digit in an array? Would it be easier to convert to an `char`, ...

### 11. Split number into digits    bytes.com

Follow this algorithm: (12345/10000)%10 = 1 (12345/1000)%10 = 2 (12345/100)%10 = 3 (12345/10)%10 = 4 (12345/1)%10 = 5 Implement this algorithm in code and off you go! EDIT: Obviously the "%10" in line 1 and the "/1" in line 5 is not needed. But I gave it this way to make the algorithm more obvious, in case you implement a loop. ...

### 13. How to break up a number into it's digits and analyze it.    bytes.com

I have a list of numbers i need to analyze, however for this just assume I only need to analyze one. I am given a six to nine digit number which I need to break into pieces from right to left. The right three digits represent an ASCII value while the middle represent a y position and the left three represent ...

### 14. How to write a program which sums the digits of a 4-digit number?    bytes.com

One of the problems you will have is that you are reading in ints, which will read in the whole 4 digit number, not just each character. If you want to do it the way you are, you'd have to read it character by character, and subtract '0' from each digit to get the numeric value. Unfortunately, this is a more ...

### 15. I want o/p for variable i/p numbers(no: of digits>5).How could I do that    bytes.com

I just replaced the data type int inside every function with long int .And the o/p went wrong.So then I decided to use int itself .By using that way I'll get output for atleast 4 digit numbers. When I tried to replace int from function names nod & pwr with long int compiler showed error as type mismatch. I also replaced ...

### 17. To reperent a number into minimum number of digits    bytes.com

Banfa re: To reperent a number into minimum number of digits Jos is talking about changing bases however it is not a solution to your problem because as Jos points out even if you change the base to conver the number ro a 1 digit number then you still have to store the base that you converted it the number to ...

### 19. how can i count the digits of number given by the user    bytes.com

Simpler method: Take input into a string. Convert that string into a number. Then number of digits is log(number)+1. Just to clarify, this is log with base 10. I'm not sure if the log function in cmath evaluates log base 10, log base 2, or natural log (log base e). To make sure, use log(number)/log(desired base). No matter what base the ...

### 20. Add 4 20 digit numbers in C    bytes.com

Hi, Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and pass the result back to a calling program in COBOL? We were able to add up to 15 digit numbers without any problems, but we started facing issues once we go above 15 digits. Thanks, Venkat

### 22. Number of digits in N!    bytes.com

Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10. Is there a way to compute that information without actually evaluating the factorial?

### 23. to reverse the digits of a number    bytes.com

Hi, Can u guys please tell me what's wrong with the following code as on giving a simple input value like: 10001, 10032, 10432, everything seems to be working fine but on giving a input value like 43211 it's not working,some value with '-' sign preceding it is getting display. i hve. tried this using long int also. void main() ...

### 25. Adding a number digit by digit.    cboard.cprogramming.com

Adding a number digit by digit. I looked at the other old post, but I could not make much from it as our codes are pretty different. I'm just trying to figure out on the adding portion and dealing with the carry. Such as if the last numbers added equal over 9 an extra position would be for 10. Code: // ...

### 26. Multiplying the digits of a number together    cboard.cprogramming.com

i need to write a program where part of it is to see if the product of the digits in an inputed integer are odd or even. It has to return a 1 if odd and a 0 if it's even. i.e. if 73 is inputed, 7*3=21 so it would return a 1. I tried to make it where it would ...

### 27. Reverse a five digit number in C    cboard.cprogramming.com

Without using loops, your options are very limited for doing this. I believe my idea of naming and using variables (posted above), was "cleaner" than your last posted code, but it still amounts to the same basic logic. There are other ways to do this, but none of them are simple enough.

### 29. Counting Digits & Numbers    cboard.cprogramming.com

#include int main(void) { int iochar, numdigits=0, numlower=0, numupper=0, numwhites=0; printf("Please enter a phrase:\n\n"); while((iochar=getchar())!=EOF) { if ((iochar=' ')||(iochar='\t')||(iochar='\n')) { numwhites++; putchar(iochar); } else if((iochar>='0')&&(iochar<='9')) { numdigits++; putchar(iochar); } else if(('a'>=iochar)&&(iochar<='z')) { numlower++; putchar(iochar-32); } else if(('A'>=iochar)&&(iochar<='Z')) { numupper++; putchar(iochar); } else putchar(iochar); } printf("%d white characters, %d digits, ", numwhites, numdigits); printf("%d lowercase have been converted to ", numlower); ...

### 31. Finding the first digit in a number....help    cboard.cprogramming.com

Hey guys, just wanted to first off say thanks for all the help in the past. I was wondering how to go about finding the first digit from a number inputted into an array. Thank you for any help. ex. enter the numbers to use: 9 45 682 120 output: the numbers are 9 4 6 and 1 Here is what ...

### 34. Program to convert 2 digit number to corresponding english word    cboard.cprogramming.com

# include main() { int digit; printf("Enter a two-digit number:"); scanf("%d",& digit); if(digit<10 || digit>99) {printf("Incorrect value!Please enter the two-digit number again.");} printf("You have entered the number "); switch (digit/10) { case 2:printf("Twenty-"); break; case 3:printf("Thirty-"); break; case 4:printf("Forty-"); break; case 5:printf("Fifty-"); break; case 6:printf("Sixty-"); break; case 7:printf("Seventy-"); break; case 8:printf("Eighty-"); break; case 9:printf("Ninety-"); break; } switch (digit%10) { case ...

### 37. How to limit user input to a certain number of digits?    cboard.cprogramming.com

I am writing a pretty simple program. There are a few different inputs I need to get from the user. 1) Single character. I am using getchar() for this, and it works well, but I've noticed one thing: If the user enters a number instead, the program will crash. How do I fix this? 2) Binary value The user types in ...

### 41. Adding a Large number digit by digit    cboard.cprogramming.com

Hi, I need to write a program where the user inputs 2 numbers and the program will add these two numbers together digit by digit because it has to be able to handle huge numbers. I am storing the input as strings and converting each digit to an integer when adding them. My problem is that the program is giving me ...

### 42. Adding a Large number digit by digit    cboard.cprogramming.com

I posted a previous thread but it is pretty much dead, so here is a new one. I'm trying to add to very large numbers digit by digit that the user inputs. I have it working as long as the numbers are the same length digit wise and the last number does not have a carry. I'm not sure how to ...

### 43. combining digits into a number    cboard.cprogramming.com

Hi, im getting digits from a file, but i need to know how to combine these digits into a number so i can store it as an int. So for example my file is 1234 i then read digit by digit like so.. current1 = fgetc( inFile ); /* =1 */ current2= fgetc( inFile ); /* =2 */ current3 = fgetc( ...

### 44. 6 digit number    cboard.cprogramming.com

/* Write a program that inputs a six-digit number, separates the number into its individual digits, multiple each separated digits by 2 and prints the digits separated from one another by three spaces each. (Hint: use the integers divisions and modulus operator.) For example, if the user types in 42339 the program should print 8 4 6 6 6 18 */ ...

### 45. C Programming Help - 'return' & digits in a number    cboard.cprogramming.com

Hello all, I need some help, so any way you can help me would be greatly appreciated. I've just started learning C language and using user defined functions, but I'm still not quite sure as to what "return ;" does or how to use it. At the bottom of my programs I've been instructed to put "return 0;" and when using ...

### 46. Count the number of vowels, consonants, digits etc.    cboard.cprogramming.com

Code: #include #include #include void scan_line(char *line, int *pv, int *pc, int *pd, int *pw, int *po); void main() { char *line; int vowels=0; int consonants=0; int digits=0; int whitespace=0; int others=0; clrscr(); printf("Enter a line of text below : \n"); scanf("%s",line); printf("%s",line); scan_line(line,&vowels,&consonants,&digits,&whitespace,&others); printf("\n No. of vowels: %d",vowels); printf("\n No. of consonants: %d",consonants); printf("\n No. of digits: %d",digits); printf("\n No. ...

### 47. Number of digits?    cboard.cprogramming.com

Excuse the newbie question but I haven't been able to find an answer to my problem. Most questions I can find on the net but I'm not sure what to search for this time. I have a small simple program I wrote that reads the number of seconds the system has been up and outputs 3 values; days, hours and minutes. ...

### 50. Number system base M, print numbers N digits wide...    cboard.cprogramming.com

Let m be an integer, greater than zero but less than eleven. Numerical strings, in which each digit is greater or equal to 0 but less than m, are numbers of the number system in the base m. The numbers 10110 and 1981, for example, are numbers of the number system in the base the 10, but only the first one ...

### 52. Numbers/digits    forums.devshed.com

First of all, it would be array[0]=1, array[1]=2 ... Secondly, we had a few people asking this exact question, oh, about a semester ago. Try searching the forums, do as much as you can on your own, and come back with some more specific questions. We want to see at least a little bit of your own code first.

### 53. Finding the number of digits    forums.devshed.com

Im trying to write a function in which you pass an integer as an argument and you get the number of digits that the integer contains back. Here is what I have, but the code is flawed: int getsize(int x) { int n=1; for(; { if(x%pow(10,n)==0) return n; n++; } } I havent tested it out, but the most obvious flaw ...

### 55. Last digit of power of two numbers    daniweb.com

#include #include int fun(int,int); int main() { int a,mod,nb,t,i; unsigned long b; scanf("%d",&t); for(i=0;i

### 59. 449 multiplied by 449, repeated 524 times, what number are the last four digits of the result ,may I ask how to use the code to achieve    codeproject.com

I imagine there is a shortcut the last N digits repeat with a cycle of at most 10^N and usually less. That's how you do these 'what is the last digit of 3^201579' type questions. But for 4 digits that cycle won't start for of the order of 1000 cycles so it's faster just to calculate it (it's not a ...