C/C++ :: Printing Partitions Of A Number Using Constraint On Number Of Values?
Apr 15, 2014
I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:
"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."
I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.
I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.
View 2 Replies
ADVERTISEMENT
Mar 22, 2015
I've got this assignment where I have to print every other number from 1 to 10.
so far I've got this.
#include <iostream>
using namespace std;
int main() {
[Code].....
wondering if its really counting from 1 to 10 and only printing every other number.
View 9 Replies
View Related
Apr 9, 2014
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
View 1 Replies
View Related
Mar 6, 2015
have this program .. i tried to make it work to give me this result output:
Code:
input array {1,3,5,1,1,8,6,6,1,3,2,1,6,8,8}
[0]
[1] *****
[2]*
[Code].....
instead i'm having asterisks at the end of the output
View 14 Replies
View Related
Feb 28, 2013
The program requires the user to enter 10 integers then print the total no. of even integer,highest even integer, lowest even integer then total no. of odd integer,highest odd integer, lowest odd integer
I already got the total no. of even integer and total no. of odd integer. But I don't know how will i get the highest even integer, lowest even integer and highest odd integer, lowest odd integer.
View 2 Replies
View Related
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
Jan 9, 2015
how to make a program in which a user is prompted to input four numbers like 1234 and then print those four numbers one by one on screen using only one variable..??
For example:
1
2
3
4
in ascending order...
I've done that with two methods but i am not sure whether the methods were correct..
View 1 Replies
View Related
Dec 17, 2013
I write this program to print the number of days for the month when the year and the month enters. This is not giving any result and i think that problem is with calling functions.
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int leap_year(int year);
string days(string mounth);
string feb(string fab1);
void main(){
int year;
View 8 Replies
View Related
Mar 6, 2015
Program that has the user enter 5 digits then asks the user what they want to know about the 5 digits. My issue is when the program goes to print the value, its a totally ill related number
10 34 8 17 50
program prints out:
2 for smallest
79 for largest
119 for sum
23.80 for average
Code:
#include <stdio.h>#include <stdlib.h>
int main(void)
{
int smallNum, largNum, count=0, sum=0, value, choice;
double avgNum;
printf("Enter 5 integers
");
printf("
");
[Code]...
View 7 Replies
View Related
Mar 18, 2012
Why my program doesn't work? Print number of vowels case-insensitively. For instance in the expression “come here”, there are 4 vowels.
#include <stdio.h>
#include <stdlib.h>
int vowels(char sentence[], char vowelletters[], int max) {
int vowelcounter=0;
int i,j=0;
[Code] ....
it just count one vowels not more.
View 2 Replies
View Related
Sep 20, 2013
I want to have one case of my switch statement to print out how many times the user has chosen other cases in the switch statement. Such as "You have pressed 2 6 times and 4 3 times."
View 3 Replies
View Related
Mar 14, 2014
I wrote this program to print prime numbers between 2 and 10 but it only prints '3'. here is the code
#include<iostream>
#include<conio.h>
using namespace std;
int prime(int x, int y);
void main(){
int n=2;
[code].....
View 6 Replies
View Related
Jun 9, 2014
I'm currently working on a code, its a wheel of fortune type of game. I have specific values of an array of size 10, and i have to get these at a random. so they would not print out in order. but how to assign each value of the random to the array.
#include <stdlib.h>
#include <stdlib.h>
#define CHANCES 5
int main(void){
int num, i;
int money[10] = { 100, 300, 200, 350, 250, 150, 175, 500, 50, 75 };
[Code] ....
View 4 Replies
View Related
Mar 5, 2014
I am trying to write a function that will count the number of distinct values in an array of N size and return that number. For example array a[n] = {1, 2, 3, 1, 2, 3, 1}. My code won't look exactly like this because I am using an array that can be modified by user input. it is part of a bigger program that will also has a function for finding the Equilibrium Index for that same array. This is what my Code looks like:
void findDistinctValues() {
int t = 0;
int j = 0;
int disValue = 0;
for( i = 0; i < arraySize; i++) {
[Code] .....
This function works but the problem is it returns 16, or the number of times that the number being compared does not equal the one it is being compared to. how do I get it to only return the number of distinct values? The data set mentioned above is what I am using for input data so it should only have 3 values.
View 9 Replies
View Related
Sep 12, 2013
I'm trying to calculate the number of distinct values entered into an array. If i enter the followings "3,4,5,6,7,7,6,e (anything that's not a number)" . I get a total of 7 but in reality it should be a 5.
Code:
#include <stdio.h>
//---------function to find the distinct values----
int find_distinct(int list[], int size)
{
int i, j,size2, distinct = 0;
for(i = 0; i < size; i++)
[Code]...
View 9 Replies
View Related
Oct 9, 2013
I was told to use a round function to round a number to give an integer number that is closer to the real value. (for example if the number is 114.67 I need to print an int value of 115 instead of 114)
I am not exactly sure how a round function works, but I am told to include math.h library. What I try doesn't seem to work.
View 1 Replies
View Related
Feb 6, 2014
In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.
int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;
[Code] ....
View 2 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Apr 26, 2013
I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .
View 1 Replies
View Related
Feb 19, 2014
So I have a template, part of a larger code, that is designed to calculate the number of multiplications it took to reach a certain number. The problem is, whenever I execute the program, mults is always printing out a strange number, perhaps its actual address.
template <class T>
T power3(T x, unsigned int n, unsigned int& mults) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == 2){
[Code] ....
View 10 Replies
View Related
Nov 20, 2014
I am attempting to write code that receives a number from the user and outputs the largest prime number underneath the user's number. There are no errors in my code, but no matter what number is imputed, the program says the largest prime number is 1. I cannot find where the issue is in the code. Here is the code I wrote:
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num);//function prototype
[Code] ....
View 2 Replies
View Related
Sep 26, 2012
I'm running a game online and designing a program to generate Enemy Stats. Basically, it's supposed to generate 25 numbers between 0 and 7(to represent 8 Attributes on a 25 Point Buy system) and count how many times each number shows up.
Here's what the code looks like:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Generate() {
int r= rand();
int s= r%7;
[Code] ....
And here's two outputs.
1: Code:
12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 Stats[0]= 25 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 0 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
2: Code:
14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 Stats[0]= 0 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 25 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
Note that the number does change, but only between runs.
View 3 Replies
View Related
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
Nov 14, 2014
Q. WAP to find the next palindrome number larger than the input number.
for eg:-
Input=25
Output=33
The program is giving correct output for number with all digits '9';
why is it not giving output.
#include<iostream>
#include<string>
using namespace std;
int main() {
int len,flag=1,count=0,num,ind;
[code]....
View 8 Replies
View Related
Mar 23, 2013
I have to write a program that will ask you to put in a number between 0 and 9 and multiply it by pi. If the number put in is between 0 and 9 then pi is multiplied but if it isnt between 0 or 9, it will say the number is not between 0 and 9 and asks you to put it in again and will repeat until a number between 0 and 9 is put in.
I have got the program working to the extent that it the number is between 0 and 9 it will multiply it by pi but if its not between 0 and 9 it will say the number is not between 0 and 9 and ask to put in a new number.
I can't work out how to get the program to repeat itself if the number entered isnt between 0 and 9.
I have enclosed the code below .....
View 5 Replies
View Related
Nov 21, 2013
I am working with C++ in Visual Studio. It's my first semester doing anything like this ever. Still, I am embarrassed that I am having trouble with this simple "coin flipping" program. The user tells the program how many times to "flip the coin" & then the program tells the user the results of each flip. You'll see I am randomly generating a 1 or a 2 within the function coinFlip to represent heads or tails. However, the problem is that if the user wants more than one coin flip, the "random" number stays the same for all of them, resulting in all heads or all tails. I am thinking this is an issue with the for loop that I have within the function coinFlip.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
[Code] .....
View 3 Replies
View Related