Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).
I have an assignment which requires me to do the following:
Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:
- The first parameter is the array to be searched - The second parameter is the integer to be found within the array - The third parameter is the size of the array - The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.
Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)
Code:
#include <stdio.h> #define SIZE 10 size_t findNumber(int *sort, const int array[],int key,size_t size); int main(void){ int a[SIZE]; size_t x;
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream> #include <fstream> #include <string> using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
I have a matrix that contains zero and nonzero elements. I want to do a function that return 3 arrays.
The first one is for nonzero elements the second array contains the corresponding row numbers of each nonzero element the third array contains the corresponding column numbers of each nonzero element.
Write a c function which takes a string(as a character array, null terminated) and reverses it. it doesn't print the reversed string -- it modifies the given string so that it is reversed.
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.
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; //binary search function bool search (int array[], int item)
Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1. HAVE TO USE FOLLOWING FORMAT:
Code: // POST: Returns the number of reversals needed to make arr[0] == 1 // if the reversal game were played on arr // Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster; [code]....
We have to write a function named fibonacci that takes an int indicating the length of the series and then store it in an array of size 20 printing the sequence from largest to smallest. Here is the small bit i have so far:
#include <iostream> #include <iomanip> using namespace std; void Fibonacci( int ); int main( ) {
[Code] ....
I just need something to get me on the right track.
How do I Write a function that takes two linked list as input arguments these linked list contain numbers like this:
num1->3->5->2->NULL (assuming that number 1 is 352) num2->4->3->9->1->NULL (assuming that number 2 is 4391)
The function should return 1 if num1 points to a linked list which represents a smaller number than the number pointed to by num2 linked list. Otherwise, it returns -1. If both linked list point to exactly the same number, returns a 0.
I'm writing a program that will implement BubbleSort and MergeSort and time them as they sort a dynamic array with N elements. These are the instructions on what my main.cpp file should do.
main.cpp Include all needed libraries for timing and random number generation while the number of element, N, is less than 100001 repeat the following.
create an array with N (initially 10) random elements sort the same array with Bubble and Merge sort time how long it takes each algorithm in microseconds (see example below) Increase N by a factor of 10 (N *= 10) Hint: you may want to put your merge sort object on the heap and delete it with every iteration of this loop
I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).
The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.
What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?
I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).
The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.
Header of the function sortMe must be as shown below:
void sortMe(int array[],int sortedIndexes [], int size, char mode)
When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.
Declare and initialize the array array.
Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.
EXAMPLE:
int array[5]={3, 5,-1,10,0}; int sortedIndexes[5]; sortMe(array,sortedIndexes, 5, 'a');
After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.
notice that the function does not e-arrange the elements in the array.
i need to write a function with an array parameter and an int parameter.
that array has to be filled with first 10 prime numbers that are exact or higher than the int parameter...and then i need an average value of those 10 prime numbers...
The problem is im not really sure how i should do the part to fill the array with prime numbers that are higher than that int??
Code:
int avgprimearray (int higharray[], int somenumber){ }
write a function accepts two arguments, an array of integers and a number indicating the number of elements in the array. the function should recursively calculate the sum of all the numbers in the array. Demonatrate the use of the functions in a program that asks the users to enter an array of numbers and prints it sum
i had done this but it wont work
#include <iostream> #include <conio.h> #include <iomanip> using namespace std;
Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
Here's the code that returns maximum sum of a subsequence from a given array. This is according to "Programming Pearls" by Jon Bentley. I have come up with an example for which this program won't work. And here's that example:
{ -10, 11, 10, -10, 2, 3, -6, 1 }
Max subsequence sum above is 21. 2nd and 3rd elements.
But the program returns 16. It sums 2nd through 6th elements and returns. Why would the writer explain something with such depth, only to give a program that doesn't work in all instances?
int MaxSum(int lo, int hi, int* arr) { if (lo > hi) { return 0; } if (lo == hi)
I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :