C :: Write A Function That Finds Integer In Array And Returns Its Corresponding Index

Mar 20, 2013

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;

[code].....

View 1 Replies


ADVERTISEMENT

C++ :: Write Function That Takes Array And Returns True If All Elements In Array Are Positive

Jan 21, 2013

Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.

View 6 Replies View Related

C++ :: Function That Returns Integer Value And Displays It

Mar 8, 2013

Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.

View 3 Replies View Related

C++ :: Function That Accepts Integer And Returns A String?

May 5, 2014

How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".

To do this would I just use an array?

View 4 Replies View Related

C :: Write A Function That Computes And Returns Score For A Permutation

Mar 21, 2014

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]....

View 2 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C++ :: Write Index Of Greatest Element Of Array

Oct 29, 2013

Create a program that will ask the user to input 10 integers of an array the program must write the index of the greatest element of the array

target output

input the integers

the greatest element is 5 and the index is 7

View 3 Replies View Related

C :: Function Which Finds Largest Contiguous Values Of Char In 2D Array

Nov 5, 2013

I am required to write a program which, when given an nxn 2D array of char, and the specified coordinates of a specific point in that array, returns thelargest number of horizontal, vertical or diagonal contiguous (side-by-side) sequence of points of that same char value that intersects with the given point.

The way I took on this problem was to:

1) First find out the number of points with the same char value up, down, right, left, north-east, north-west, south-east, and south-west of the given point.

2)Add up+down+1(the one is for the point itself), north-west+south-east+1, etc...

3) Finally I compared the four values (updown, rightleft, NESW, NWSE) and returned the largest one.

Well, that's how the program is supposed to work in theory but as you can probably guess it doesn't work. In addition to telling me what I'm doing wrong, is there a simpler way to do what I am trying to accomplish?

Here's the code:

Code:

int findLongest(char **board, int n, int row, int col)
{
char current;
int rightleft, updown, NESW, NWSE;
int r, c, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, d;
int t1=1, t2=1, t3=1, t4=1, t5=1, t6=1, t7=1, t8=1;
current=board[row][col];
//check Above: col remains the same
for(r=row-1;r>=0||t1!=0;r--)
//with the condition r>=0 I made sure not to accidentally check values outside of the array

[Code]...

View 1 Replies View Related

C :: Write A Program Which Finds Difference Between Two Arrays

Mar 9, 2013

My tasks was to write a program which finds difference between two arrays (elements which are in first array but not in second and vice-versa). Program works, but something wrong is with the memory allocation for array.

My code is:
main.c Code: #include <stdio.h>
#include <stdlib.h>
#include "header.h"

[Code]....

View 5 Replies View Related

C :: Function That Returns ARRAY And Its SIZE?

Dec 24, 2013

to return the array i shall make a pointer function thats ok.. but how do I get the size return if i dont know the size?

if I need to make AXB=C and output C my new array doesnt have a size..

View 7 Replies View Related

C++ :: Write A Template That Accepts Argument And Returns Its Absolute Value

Nov 19, 2014

Write a template that accepts an argument and returns its absolute value. The absolute entered by the user, then return the total. The argument sent into the function should be the number of values the function is to read. Test the template in a simple driver program that sends values of various types as arguments and displays the results.

#include <iostream>
using namespace std;
template <class integertemplate>
integertemplate totalint (integertemplate integers) {
cout << "How many integer values do you wish to total? ";
cin >> integers;

[Code] .....

View 8 Replies View Related

C++ :: Writing Strings Into Array Index Within A Function?

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

Code:
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
int main()

[Code].....

View 1 Replies View Related

C/C++ :: Writing Strings Into Array Index Using Function

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

#include<iostream>
#include<string>
using namespace std;

void viewMonth (string month[], int num);
void dayNote (string month[]);

[Code] .....

How do I make void dayNote function work so I can cin a string into the desired array index?

View 3 Replies View Related

C++ :: Print Stars Function - Corresponding To Array Index Size

Nov 24, 2014

I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:

#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);

[Code] ...

View 3 Replies View Related

C++ :: Function To Determine Largest Value In Array And Then Outputs Value And Index

Dec 5, 2013

I'm trying to create a function that determines the largest value in the array and then outputs the value and index. I want to values in the array to be random so I tried using the rand function, although I'm not sure where I'm supposed to put it. My main problem (I think) is outputting the correct values...

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void lastLargestIndex (int numbers[], int arraySize);
int main(int argc, char** argv) {
int number, arraySize = 50;

[Code] ....

View 2 Replies View Related

C++ :: Return The Digit At User Specified Index Of Integer

Oct 10, 2014

Return the digit at the user specified index of an integer. If the integer has n digits and the index is NOT in the range 0 <=index <n return -1 Start the digit numbering at 0. Example, if user input is 4 (index) and the integer equals 123456790 the return value for the function is 5 (start index at 0) ; if user input is 40 (index) and the integer equals 123456790 the return value for the function is -1

#include <iostream>
#include <istream>
#include <cstdlib>
#include <cassert>
#include <string>
using namespace std;
int getIndex(int, int);

[Code] .....

View 4 Replies View Related

C/C++ :: Frequency Distribution - Finds All Numbers In Array That Show Up Exactly 5 Times

Oct 9, 2014

Create a program that finds all numbers in an array that show up exactly 5 times. I am trying to solve this issue by making a frequency distribution via two loops and two arrays, but I am having trouble getting my loop to not recount a number it has already counted.

For example, if you enter ten 1's into the "entered Numbers" array I want it to store a count of 10 in frequencyarray[1]. Instead it is storing

frequencyarray[0]10
frequencyarray[1]9
frequencyarray[2]8
etc...

#include <iostream>
using namespace std;
void enternumber(long[], int);
int main() {
int size;
int numbers5=0;

[Code] .....

View 14 Replies View Related

C/C++ :: How To Return Array Of Integer From A Function

Apr 2, 2014

The problem is how to return an array of integer from a function?

I'm writing a C program code to return an array of integers ( grades of students ) to the main function!

View 9 Replies View Related

Visual C++ :: Write A Function With Array And Int Parameter?

Nov 25, 2012

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){
}

View 1 Replies View Related

C :: Function That Returns A Char

Sep 4, 2013

I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.

Code:

//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;

[Code].....

View 11 Replies View Related

C++ :: Minesweeper - Function Always Returns The Same

Jun 24, 2013

For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:

bool setzen(int x, int y){
if(feld[x][y]!=3){
return mine=false;
}

[Code]....

Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.

View 6 Replies View Related

C++ :: How To Use Function That Returns Vector

Oct 7, 2014

How can I show elements of a vector that is returned by a function in main() ?

Code:
vector<int> merge_sorted(vector<int> a, vector<int> b){
vector<int>temp;
int count = 0;
if(a.size() < b.size()) count = a.size();
else count = b.size();

[Code] .....

View 12 Replies View Related

C :: Why Integer With Array Change After Passing Through The Function

Apr 12, 2014

Code:

#include <stdio.h>
void define (int integer, int IntArr[0], int *IntP);
int main(void)
{int integer = 0, IntArr[1] = {0}, IntP = 0;
define(integer, IntArr, &IntP);

[Code]...

Why does the integer with array change after passing trough the function and the normal integer doesn't? (I know why the normal one doesn't, but I dont get the array one)

View 1 Replies View Related

C++ :: Function That Stores Number Into Integer Array?

Apr 30, 2013

I'm writing a function that stores a number into an array. If the number is greater that the lowest number in the array then it replaces it. The array size is 10. When the number is stored in the array. The lowest number must then be remove.

View 3 Replies View Related

C++ :: Function To Receives Integer Array Along With Its Length

Apr 2, 2014

How to write a function that receives an integer array along with its length. the function calculates and returns the sum of the squares of all the odd numbers in the array?

View 2 Replies View Related

C/C++ :: Write A Function That Accepts Two Arguments / Array Of Integers

Feb 16, 2014

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;

[Code].....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved