C :: Program That Fills Array With 10 Random Numbers Between 1 And 20
Apr 16, 2013
i have a programming problem and i am unsure of what the final part is.the question is:
Write a program that fills an array with 10 random numbers between 1 and 20, displays the 10 numbers, and finds the sum of the 10 numbers. Call the getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.
i am just really unsure of what this is--getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.what i have got so far is;
Code:
#include <stdio.h>
#include <stdlib.h>
#define ARY_SIZE 10
int main() {
int randomNumbers[ARY_SIZE], sum = 0, i;
[Code]....
View 1 Replies
ADVERTISEMENT
Mar 3, 2014
When I go to run the Fibonacci function ( fib ), it begins to return incorrect calculations towards the higher numbers, but then seems to correct itself for a little bit, but then does it again and ultimately crashes. And the program seems to be crashing at random numbers. Sometimes the it will make it up to F(55), other times it will only get to F(20).
Also, when I go to run the program on a Linux server, it segfaults, but it doesn't when I just run it on my IDE. the function adds two arrays with individual digits together. It does this to allow the program to add numbers that would exceed the boundaries of INT_MAX.
Here is the header file "Fibonacci.h":
Code:
#ifndef __FIBONACCI_H
#define __FIBONACCI_H
typedef struct HugeInteger
{
// a dynamically allocated array to hold the digits of a huge integer
int *digits;
// the number of digits in the huge integer (approx. equal to array length)
int length;
} HugeInteger;
}
[code]....
View 12 Replies
View Related
May 6, 2013
#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
[Code] ....
Write a program that keeps generating two random numbers between 1 and 10 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.
Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.
After presenting the number of pairs of numbers specified and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.
When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.
After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.
Use a nested for loop to display the table; a bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.
The following is a sample interaction between the user and the program:
Enter the number of questions to ask: 5
1. What is 3 x 9? 27
Right!
2. What is 2 x 7? 14
Right!
3. What is 8 x 9? 63
Wrong! 8 x 9 = 72
4. What is 6 x 3? 21
Wrong! 6 x 3 = 18
5. What is 2 x 9? 18
Right!
You got 3 out of 5 right which is 60%.
Play agian? [y/n] n
View 10 Replies
View Related
Nov 1, 2013
output should look like this -
So far i have this
[code]#include <iostream>
#include <time.h>
using namespace std;
int main() {
srand(time(NULL));
[Code] .....
I am getting these errors when i compile it
random.cpp: In function âint main()â:
random.cpp:23: error: expected â,â or â;â before numeric constant
random.cpp:24: error: âRâ was not declared in this scope
random.cpp:25: error: âRâ was not declared in this scope
random.cpp:26: error: âRâ was not declared in this scope
random.cpp:27: error: âRâ was not declared in this scope
random.cpp:28: error: âRâ was not declared in this scope
View 3 Replies
View Related
Feb 10, 2014
The program must print out 5 random numbers, from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same....
for example
1,2,3,4,5
6,7,8,9,10
....
...
..
here is my code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
int xRan1;
[Code] ....
View 2 Replies
View Related
Mar 1, 2014
I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.
Code:
/* Evan Wentz */
/* Pike - ET2560 */
#include <stdio.h>
#define MAX_ACCTS 100
int accounts [];
double balances [];
[Code] ....
I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...
View 6 Replies
View Related
Jan 11, 2015
i cannot print the values stored in the array ?
Code:
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
double randf();
[Code] ....
View 7 Replies
View Related
Feb 27, 2013
So we're having an assignment for school where you code a Roulette game which simulates you playing and you can choose how many times you "play" to check how many times you'd win (if that makes any sense, im german :P)
Anyways, the problem is how do i store all the random generated numbers in an array while NOT doing this (it's just a snip):
Code:
void randomzahl(void){
int i;
int zahl5[5];
int zahl10[10];
int zahl100[100];
int zahl1000[1000];
int zahl10000[10000];
if(runden == 5)
[Code]...
View 3 Replies
View Related
Oct 5, 2013
How would i go about loading an array with random numbers with in a range. For example, loading an array of 500 elements with random numbers in the range of 50-100.
View 9 Replies
View Related
Feb 24, 2013
Below is my code for a program that is suppose to generate and display six unique random numbers (between 1 and 54). The issue seems to be in my check for duplicates. I know what I am doing wrong but can't seem to find a way to fix it. I think it is getting stuck in an endless loop because the way I have written it looks like it checks the first value against itself which will of course look like a duplicate everytime.
Code:
#include<iostream>
#include<ctime>
using namespace std;
//function prototype
[Code]....
View 1 Replies
View Related
Apr 16, 2014
I am a very fresh c programme user, and need to fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code?
When I printf the array it always ends up with random numbers. Below is my programme which is just designed to read a doc and print it back out, as well as the text doc it is designed to read.
View 3 Replies
View Related
Jun 28, 2012
I am trying to sort an array of random numbers by passing it to a method Sort(), sort the array, and then pass the entire array back to the calling program. Each time I run this though, the array doesn't seem to sort. I'm not sure if the problem lies with my sorting algorithm or if it has something to do with calling the function.
Code:
static void HighAverage(int[] a) {
for (int i = 0; i < a.Length; i++) {
if ((i + 1) % 10 == 0 && i != 0)
[Code].....
View 5 Replies
View Related
Jan 31, 2013
My program generates an array of random numbers. I want to then search a specific number within the array. If the number is in the array then a message apopears on the console saying that its there. I'm using the binary search algorithm to do this.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;
int size;
int getSize() { return size; }
[Code] ......
View 2 Replies
View Related
Oct 15, 2013
Assignment on making a program like candy crush but it is called as number crush.
View 3 Replies
View Related
Oct 24, 2014
I need to find the smallest number in my 10x8 arraygrid with random numebr filled in it
Here my Code:
#include <iostream>
using namespace std;
int main() {
int total,average,smallest;
int row=0;
int col=0;
[Code] ....
View 2 Replies
View Related
Nov 6, 2014
I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.
Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.
Code:
#include <iostream>
using namespace std;
int main() {
int input;
int number;
int row=0;
int col=0;
int Array [12][10];
[Code] ....
View 1 Replies
View Related
Aug 31, 2013
I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!
Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
[Code].....
View 4 Replies
View Related
Nov 22, 2014
This is in c. Write a program which asks for X numbers, and stores them in an array.
The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number
Make an array of the indexes where the number was found, and then format your output to match my output.
Sample Run:
How many numbers would you like to enter: 5
Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2
The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4
Press any key to continue . . .
View 10 Replies
View Related
Oct 6, 2013
Write a C program that sorts an unsorted array of 5 integer numbers in ascending order by swapping numbers repeatedly. Specifically, first prompt the user to input 5 numbers and store the numbers in an array. Then, if the numbers in the array are not in ascending order, ask the user to provide the indices of two numbers in the array that the user wants to swap. If the user does not enter valid indices (i.e., outside 0 to4), then re-prompt the user to enter new indices. Continue prompting the user to provide indices of numbers to swap until the array becomes sorted in ascending order. Finally, when the array becomes sorted, the program should print "The array is now sorted in ascending order".
Implementation Requirements
Use the #define directive to define the size of the array.
Implement a function called "checkArrayOrder" to check whether an array is in ascending order or not. The prototype of the function is
"intcheckArrayOrder(int arr[], int size);". The function should return
1 if the array passed to the function is in ascending order0 if the array passed to the function is not in ascending order
Define the function prototype in your program.
Implement a function called "swap", whose prototype is "int swap(int arr[], int size, int i, int j);" which swaps the numbers in positions "i" and "j" of the array passed to the function and returns
1 if the indices"i" and "j" are within bounds (i.e., between 0 and 4) and the swap operation is performed correctly.
0 if the indices"i" and "j" are outside bounds so that the swap operation cannot be performed.
Define the function prototype in your program.
Use the function "checkArrayOrder" whenever your program needs to check whether an array is in ascending order or not; and the function "swap" to swap the numbers the user specifies (Note that, you should check whether the user provided indices are valid inside the function "swap" and not inside "main").
here is my code so far
Code:
#define ARRAY_SIZE 5
void main()
{
int i, array[ARRAY_SIZE];
printf("Enter %d numbers
", ARRAY_SIZE);
for(i=0; i<ARRAY_SIZE; ++i)
scanf("%d", &array[i]);
[Code] .....
I'm just not sure how to proceed. I'm not really sure how to progress the checkArrayOrder function to the swap function (in the if statement).
View 7 Replies
View Related
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:
Display each elements of the array
Display the sum of all the elements of array
View 1 Replies
View Related
Nov 25, 2014
I have to make a program that takes several numbers into an array into a function, and send them back into the main function multiplied by 1.13. This is what I have so far:
#include <iostream>
using namespace std;
void connell(int&n[20])
main() {
int num[20];
[Code] ...
I do not know how to get numbers from an array from a main program to a function.
View 2 Replies
View Related
Jan 18, 2015
I am trying to write a program that adds numbers to an array. The array capacity starts out at 2, then doubles whenever the size reaches capacity. The program works perfectly fine when the array needs to be expanded. So I have narrowed down the issues into this one function (_dynArrSetCapacity)
Creates original array
DynArr* createDynArr(int cap) {
assert(cap > 0);
DynArr *r = (DynArr *)malloc(sizeof( DynArr));
assert(r != 0);
initDynArr(r,cap);
[Code]...
If i do createDynArr(10) for instance in the main, the program works perfectly, as it never gets expanded
View 3 Replies
View Related
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the followings:
Display each elements of the array
Display the sum of all the elements of array
View 4 Replies
View Related
Mar 7, 2013
Create a program that display all the fibonacci numbers and display the 21st digit using array.
Here's my code:
#include <iostream>
using namespace std;
int main () {
cout<<" This program shows a series of fibonacci numbers
"<<endl;
[Code] ....
View 2 Replies
View Related
Feb 22, 2013
I am working on a program which creates a large pointer array of numbers and then performs several iterations of operations in them.
Code:
int * u = new int[N];
double * nu = new double[N];
int * nud = new int[N];
for (int i=0;i<M;i++){
for (int i=0;i<N;i++){
u[i]=0;
nu[i]=0;
[Code]...
If M is small enough then there are no problems in the program. However once M is large enough I get the "unhanded exception":
std::bad_alloc at memory location 0x0026f728..
Since I am just reusing the same arrays, and since I am able to make it through a few iterations, I didn't think it could be a memory issue. If it is, is there a way I can clear the data completely after each iteration?
View 4 Replies
View Related
Oct 17, 2014
I'm trying to make a C++ program that generate 6 random numbers ( from 100,000 to 999,999 ), okay, so I wrote a few lines..
Code:
srand(time(0));
for (int i = 0; i < 5; i++)
{
std::cout << 100000 + (rand() % 999999) << std::endl;
}
The problem is, that it generates numbers like this:
117,207
123,303
131,083
... etc etc..
They're all starts with 100K, i want them to be an actual random..
View 8 Replies
View Related