Hello everyone,
Im kinda lost, my task is :
Number of integer​​(positive and negative) on the input.
Write a table of the number of individual digits in the input numbers.
input: 1, 1, 2, 56, 89
output:
1 = 2;
2 = 1;
56 = 1;
etc...
But problem is that i can use only iostream and cmath library,no breaks, no vector,no functions just array,for or while loop or another
How do i find if the number is already there ? and add +
I don't understand your output. '56 = 1'? I thought you were just counting digits, so it would be '5 = 1' and '6 = 1', no?
Assume you are just counting digits, my first suggestion would be to start small.
First, just figure out how to get the digits of a number. You can do this with the % operator.
For example, 123 % 10 == 3, so this "extracts" the least-significant digit.
Then, doing 123 / 10 = 12 removes the least-significant digit. You can do this in a loop to get each digit.
Then, you need to hold on array of size 10, one element for each digit, that keeps track of the digit counts for each digit.
So you'd have some loops:
1 2 3 4 5 6 7 8 9 10
int digit_counts[10] {};
for (each number entered)
{
loop through digits of number
{
add counts inside digits_count[digit]
}
}
at the end, print each index and count of the digit_counts array
Note: In case you weren't aware, that code that @Ganado gave you is pseudocode, which is not actual code. It is basically like taking notes; it allows you to work out the logic of a program, and then you can use that pseudocode to write the actual code.
Don't try to compile it, as you will get a ton of errors.
You might use std::vector<int>.
If you don't want use STL, try to write your own vector(or dynamic_array), because you don't know how many numbers are there.
You might use a lot of new[]s and delete[]s.