Finding all possible equasions

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Finding all possible equasions

Post by maboroshi »

Hello everyone

I am thinking of writing a function and wanted your opinion on the best solution to solve my problem

I have the number 9 which is the answer to the question and all possible questions that would equal that answer

However discovering the question is where I am finding it difficult.

I would like to implement a way to take the number 9 and print all possible methods of addition (+) of two numbers no higher than 9 themselves which the resultant would equal 9. As an example:

0 + 9
1 + 8
2 + 7

---------

9 + 0
8 + 1
7 + 2

Any ideas.

*cheers

Maboroshi

User avatar
f4Gg0t_43
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 245
Joined: 13 Sep 2008, 16:00
15
Contact:

Post by f4Gg0t_43 »

Type in number, and it will output all the addition possibilities (without using negative numbers). It can also go as high as you want for the number.

Code: Select all

#include <iostream>
void func(int a){
    for(int i=0;i<a;i++)
        std::cout<<'\n'<<i<<'+'<<a<<'='<<i+a--;
}
int main(){
    int number;
    std::cin>>number;
    func(number);
    return 0;
}

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

cool

Post by maboroshi »

Cool thanks guys

f4Gg0t_43

this did it thanks man *cheers

Post Reply