Hey guys just trying to write a simple program where I ask the user to in 2 numbers.
So if the user puts the 6 first and then let say 2
i print back the result 1 and 5,2 and 4,basically what ever adds up to 8
Code:
#include <stdio.h>
#include <math.h>
int total;
int numbers;
int calculate(x,y);
int amount;
int main()
{
printf("Enter the total :\n");
scanf("%i", &total);
printf("Enter the number of combinations:\n");
scanf("%i", &numbers);
amount=calculate(total,numbers);
printf("The possible combinations for total are %i",amount);
}
int calculate(x,y)
{
}
////////////////////////////////////
My sample output would be
Enter the total:
6
Enter the number of combinations:
2
The possible combinations for total are
1 and 5
2 and 4
///////////////////////////////////////////////
I'm going to limit my total allowed entered in staring off to be 9 and combinations 2 to make it easier starting and then increase them as I go on.
Just with my is there an easy way to find the sum of a specific number or will I have to make a big massive array or something?
This is a simple problem, so you should look for a simple solution.
The first input is a total, so you might call the variable "total".
The second input is the number of times we give an example of two numbers that add up to that total. We could
also call it a number of "iterations", or "i" for short.
Starting from 1,
1, and (total-1), is an example.
2, and (total-2) would be the next example.
i, and (total-i) would be the final example.
So create a for-loop starting at 1, and ending at i that prints out i and (total-i).