C++ :: Find Sum Of All Digits In Number Until Sum Becomes A Single Digit

Jan 24, 2015

Given an integer, find the sum of all the digits in the number until the sum becomes a single digit. E.g. sum of digits of 9264 = 21. Then sum of 21 = 3.

View 2 Replies


ADVERTISEMENT

C++ :: All Possible Combinations For 4 Digits From A 5 Digit Number

Jun 23, 2014

How to get all the possible combinations for 4 digits from a 5 digit number. I need a pair that has both 5 digits and four digits. their sum must be equal to a five digit user input. i.e.

user input : 14690
output:
14690 has pairs 12345 + 2345
2345 came from 12345
lets say that x = 12345 and y =2345
besides y == x%10000

other formula can i have since if i use % and / i will have a lot of declarations....

View 2 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C/C++ :: Program To Find Number Of Digits In Number?

Aug 20, 2014

In the c pgm to find number of digits , if I am giving 001 as the input number ,why I am not getting the no. of digits as 3?

View 2 Replies View Related

C :: Function To Generate A Number - How To Find Same Digits

Nov 15, 2014

I use rand function to generate a number which consists of 3-5 digits(e.134,1435,73463..). The user decides whether he wants a 3 digit,4 digit or 5 digit number.After that,the user tries to guess the number.Its like mastermind game.The user will enter a number (with the same amount of digits) and the program will calculate how many digits from the secret number he has found and also how many digits he has found in the correct position(e.if the generatir produces the number 32541 and the user tries the number 49581 the program should tell him that he found 3 digits (5,1,4) and 2 digits in the correct position(5,1)) so that after some tries he finds the secret number.My problem is with the functions so that i can compare the digit of each number,find the amount of same digits and the amount of digits in same position.

View 5 Replies View Related

C :: How To Find Number Of Elements In Single Line Of Dat File

Oct 30, 2013

How would i get the total amount of elements From the input file(The .dat file) and then store them in a variable?Here is an example to show you what i want. If a line on the .dat file looked like this

1 2 3 4 5 6 7

How would i find the total number of elements? For example the total number of elements in this line would be 7.

View 9 Replies View Related

C++ :: Input Integer Then Output Both Individual Digits Of The Number And Sum Of Digits

Oct 11, 2014

My problem needs to prompt the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. An example would be entering 8030 and it spits out 8 0 3 0 as well as 8+0+3+0=11 and it needs to work with negative numbers.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int base;

[Code] ....

Now I don't know if any of this is right a hint my professor gave us is that to get the fourth digit you would do base mod 10 and to get the first digit you do base divided 1000...

Code:

{
int power;
int counter=0;
int value=1;
cout << "Enter the power of 10 you want: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Swap A Digit From A Number With Another Digit Using Function

Oct 26, 2014

Write a function which will take 3 arguments. The function needs to return a new number which is formed by replacing the digit on a given position in the number with a digit which is carried as an argument (the position in the number is counted from right to left, starting with one). Write a main program which will print the newly formed number.

Examples:
A function call of 2376, 3 and 5 should return the number 2576
A function call of 123456, 4 and 9 should return the number 129456

What I succeeded to do so far:
Figure out the logic for swapping the digit and write working code for it (in the main function).

What I failed to do so far:
Write a function which will return the desired result.

What is my problem:
I tried writing a function to do this, but as you see from my calculations, my result is divided in 3 parts. I don't know how to return more variables from a function.

Code:

#include <stdio.h>
int main() {
int inputNumber, swapPosition, swapDigit;
scanf("%d%d%d", &inputNumber, &swapPosition, &swapDigit);
int i, numberPart1 = inputNumber;
for (i = 1; i <= swapPosition; i++)

[Code] ...

View 8 Replies View Related

C++ :: Find Remainder Of Two Many-digit Numbers

Aug 25, 2013

if i have two integers, say number1 and number2, stored in arrays where each index is a digit of the number (i.e. if my numbers are 321 and 158, then number1 = {3,2,1} and number2 = {1,5,8}), can i find the remainder of number1/number2? assume number1 > number2.

View 1 Replies View Related

C++ :: Find The Highest Digit Within C-String

Oct 27, 2014

I can't find the highest digit within c-string. Ithe user was to enter 1234. the highest shall be 4 but can't get that number.

int Hnum(char* str) {
//int size = 0;
int H = 0, remainder, div =0;
int intstr = atoi(str);

[Code] ....

View 2 Replies View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.

Sample Output 1:

8-bit Binary Number => 11111111
Decimal Number = 255

Sample Output 2:

8-bit Binary Number => 10101010
Decimal Number = 170

Sample Output 3:

8-bit Binary Number => 101010102
Number entered is not a binary number

#include <iostream>
using namespace std;
int main()
{
int num;

[code]....

View 2 Replies View Related

Visual C++ :: Find The Location Of Certain Digits From User Input

Sep 24, 2013

I have been trying to finish this code (function) for a while now, but am stuck on the last part. In this code, I prompt the user to select a number of integers and any number of digits and then find the smallest and largest value within these digits. On the next part, I am supposed to determine which of the given digits the smallest and largest are located such that the output should be:

Digit _ can be found in integer number(s): _, _

Here is what I have tried:

Code:
int digitSizeLoca() {
int userNumInteger;
int* iPtr;
int* iPtr2;
int* iPtr3;
int value;

[Code] ....

Seems to do the job, but it always outputs 1, 2...

View 4 Replies View Related

C++ :: Game Of Pick 4 - How To Find Similar 4 Digit Numbers In Array Of 120

Jun 6, 2014

I have a question regarding finding similar 4 digit numbers in a pool of 120 numbers

Below is an linear single dimension array of 4 digits

There are 120, 4 digit numbers in total

My question is this - How can I code in C - a function that looks through all the 120, 4 digits to find similar numbers

Example - 2095 is similar or matches to - 0950, 5095, 5250, 5269 - i.e having 3 of the digits that are the same in the 4

The code must print out 2095 + all the matched numbers

If the Matched or Similar numbers are less then a certain number n - that number is discarded and the code should go onto the next number

2095095053741884864037233464846523768035
4340520865405306753553226100610753235081
1160346508409698809176715645765520676974
2398509523307591808464215318649140982136
2388015030217584311064844010520796345135
5376565155806436092330366745536969232311
4351519149310340620918615194324744655250
5330634052450976531053882380318069765623
2186677440212394367468519636617536556706
5274239549814534091052060118499521655275
6351091153944834003545212360098053955218
4835406061305276769161885611376776845269

I have written some code below but it is not working ...

Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <memory.h>
#include <dos.h>
FILE *fileptr;
FILE *fileptr1;

[Code] ....

View 10 Replies View Related

C++ :: Converting 4 Digit Number Into BCD Number?

Sep 10, 2014

I'm having trouble converting a 4 digit number into a BCD number, in the program I did below I was able to convert a 2 digit number into BCD, but I do not know how to convert a 4 digit number or how to start it.

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])

[code]....

View 2 Replies View Related

C :: Storing A 10 Digit Number

Dec 9, 2014

I wanted to find all the prime until a specified limit in C. I use the Sieve of Eratosthenes. But when I define the limit to anything more than a 7 digit number the program terminates.

Code:

#include<stdio.h>
#define limit 1000000000
int main(void)
{
unsigned long long int i,j;
int primes[limit] = {0};
//int count =0;
for(i=2;i<limit;i++)
}

[code]....

I believe that this might be because the size cannot be declared array cannot be more than the a 7 digit number. I think so. how to store a 10 digit number in C?And can't unsigned long long hold a 10 digit?

View 1 Replies View Related

C :: How To Get Each Digit Of A Number From Array

Apr 14, 2013

I have an array join[], some of its elements are single digit and some are numbers. I want to print the output in single digit form.Like in below code

Code:
int join[3]= {12,0,3};
int split;
int j;
for (j=0;j<3; j++) {

[Code] ....

My code won't consider array element "0". How can i fix it for that too.

Code: I want output should be like
1
2
0
3

View 4 Replies View Related

C++ :: Trying To Remove First Digit Of Any Number

Dec 18, 2013

I am trying to remove the first digit so if the user enters 12345 it should output 2345 the code i have works only for removing the last digit how would i go about removing the first one?

#include <iostream>
using namespace std;
int removeFirst(int n);
int main(){
int n, m;
cout << "enter number" << endl;

[Code] ....

View 4 Replies View Related

C/C++ :: How To Store 50 Digit Number

Sep 14, 2013

what is the data type of a variable to store 50 digit number in c? and what is the data type specifier for that?

View 5 Replies View Related

C++ :: Remove Digits In Number

Jul 18, 2013

I know how to remove digits in number from right to left.For example: the number 319. If I do (number /= 10), I get 31.how can I remove digits in number from left to right.For example: the number 319. If I will do something, I will get the number 19.

View 15 Replies View Related

C++ :: Reversing Five Digits Number

Mar 9, 2013

//Program to reverse 5 digit number

#include <stdio.h>
void main() {
int num, i = 0;
char rev[5];
printf("Enter any 5 digit number

[Code] ....

WHILE DISPLAYING i am not getting correct output. whats wrong in rev[] array.

View 7 Replies View Related

C++ :: Print Last Digit Of Number Output Always Become 6?

Oct 26, 2013

i just started learning programming and i just wanna know how come when i try to print the last digit of a number the output always become 6?

View 4 Replies View Related

C :: Storing 12 Digit Number On 32 Bit Architecture

May 8, 2014

So I have to ask the user to enter a positive 12 digit number, and it has to be 12 digits exactly. I thought I'd do

Code:

unsigned long long int x;
do{...}
while(!(x>99999999999 && x<1000000000000));

This would obviously be fine on my 64 bit machine, but the code will be ran on a 32 bit one, where unsigned long long is, if I'm not mistaken, 32 bits. Which has a max value of 4 billion and something.

View 13 Replies View Related

C++ :: Three Digit Random Number Generator

Aug 4, 2013

How to produce a code that will satisfy the following constraints. I don't really know C++

- Produces a random three number positive integer between 001 - 504.

- Changes the output number every 24 hours on a website.

View 2 Replies View Related

C++ :: Encrypting MAC Address To 4 Digit Number

Apr 4, 2014

I want to encrypt Mac address to 4 digit number which can be decrypted to original MAC address.

View 9 Replies View Related

C :: Input Number - How To Store 500 Digits

Oct 30, 2013

"Every number has at most 500 digits" under input. 500? How am I supposed to store that? And what if someone multiplies 999 ...(500 times) * 999 ... (500 times) ? I seriously doubt that my computer can store that! Is that just some huge value used to scare people off or is there some sneaky trick that I am unaware of?

I am done with the program, but won't post it, Lets not ruin the fum for ohers...Does that 500 limit also applies to result of operation?So max length of an input number is ~22 digits ? But still, how do I store 500 digits? Array would be a lot of wastage of memory (though I do have 256MB available).

View 2 Replies View Related

C++ :: Printing Permutations Of Digits Of A Number?

Feb 8, 2013

I have been trying to write a recursive function to print the permutations of a n-digit number. This is the logic that i am trying to use.

1.call the permutation function,

2.keep the first digit in the first place and send the remaining 2 digits back to the permutation function recursively.

3.keep one of the two digits received and send the remaining digit to the permute function.

4. keep doing this till only one digit remains. this is the smallest solution so return it.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved