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 ... |
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 ... |
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 ... |
Efficient way to determine if the number has identical digits in C
|
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?
|
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 ... |
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()
{
...
|
|
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
|
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 ... |
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, ... |
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. ... |
|
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 ... |
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 ... |
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 ... |
|
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 ... |
|
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 ... |
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 |
|
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? |
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() ... |
|
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: // ... |
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 ... |
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. |
|
#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); ... |
|
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 ... |
|
|
# 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 ... |
|
|
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 ... |
|
|
|
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 ... |
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 ... |
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( ... |
/* 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 */ ... |
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 ... |
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. ... |
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. ... |
|
|
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 ... |
|
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. |
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 ... |
|
#include #include int fun(int,int); int main() { int a,mod,nb,t,i; unsigned long b; scanf("%d",&t); for(i=0;i |
|
|
|
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 ... |
|
|