So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:
Code: void Llogaritje1(int t[3][3],int &i, int &j){ int y,l; for(y=0;y<3;y++){ for(l=0;l<3;l++){ if(t[y][l]==9){ i=y; j=l; break; } }if(t[y][l]==9) break; } }
But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.
I am trying to make my program read a bunch of numbers in an array to find its maximum and minimum. the program will ask the user to enter in as much number as possible until they enter a non number/letter. i got my program to find the maximum value but the program couldn't read the minimum value. it always says zero. also everytime i enter the number 0, the program will just finish its loop statement. If i typed in a negative number, it'll read the negative number as its minimum.
Code: #include <stdio.h> int main() { //-------variables------------------ double list[1000]; // can hold 1000 items int i; char letter; int max = list[0]; int min = list[0];
Most of this program is working correctly, however when I get to the part on lines 70 to 78 to try and use the function on lines 103 to 113 to find out each diagonals value and then print each one back. But when this runs it only returns the value for [0][0] for each run through the loop and I'm not really sure why. I know its probably something simple but I'm just missing it,
Code: 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 #define MAX 100 5 6 void display_menu(); 7 int check_option(int);
I've been trying for over an hour to think of the logic to find the mode of an array.I left out code for initializing the arrays, but all the values in the array are between 0-9. Check out my code below.
Code:
int mode( int array[], int size ) { int i; int count; int max = 0; int num = 0; int mode;
I am attempting to write a program that takes a number(picked by the user) of test scores in an array then calculates the average and outputs the number of passed and failed tests.
On a side note I am attempting to use array notation in the main function and pointer notation in the other functions
#include<iostream> #include<iomanip> using namespace std; int numScores; int counter = 0; double *scores; //Function Prototypes
i just want to check to see if one word (string) or one sentance is equal to any others within an array. My code
so basically i want to check if a is equal to either "sleep", "in", or "bed". Or even if the string within a is equal to "sleep in bed" as one string.
I have used the following but even if i get it correct and it says correct it says incorrect another 2 times because it is saying yeah you have gotten one right out of the possible 3. Even if I type "sleep in bed" it still does it (prints out incorrect another 2 times. Also are there any good books to start off with c++?
"Write a program in C that finds the element of an array which all the previous are smaller and all the next are bigger than that.If there are more than one print the biggest. If there isn't any print "ERROR" .
EXAMPLE
If the array has 10 elements like this : {2,3,4,6,5,7,8,10,9,8}
The correct answer is 7 , because 2,3,4,6,5 are smaller than 7 and 8,10,9,8 are bigger than 7.
I am working on it for 2 weeks and I can't find a working solution />/>/>
There is the first try :
#include <stdio.h> #include <stdbool.h> int s_data[10]={2,3,4,6,5,7,8,10,9,8}; int main() { int result,i,j,s_len ,tmp1,tmp; bool GT_PREV,ST_NEXT;
after staring at this for awhile, I can't figure out why it won't work. It prints out numbers from 0 to 100, but will print out an absurdly high number as the highest number, like 790 or 640. I can't see why.
Code: #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int find_highest(int array[]); int find_highest (int array[], int size) { int highest_num; for (int i = 1; i < size; ++i) { if (array[i] > array[i-1]) {
I'm supposed to find the biggest number (largest value), in any given array A with n numbers. (no floats)
My thoughts here are, check if A[0] > A[1]. if yes, check if A[0] > A[2]. If no, check if A[1] > A[2] etc.
I'm not sure how I can do this in code. I'm thinking if A[0] > A[1] is true, then set A[0] = A[k]. Kind of set it aside, and use that for the next if test. But I'm not sure how to do it.
This is my code so far.
Code: int main(){ int A[7] = {12, 6, 9, 33, 2, 25, 53}; int i, k; k = 0;
[Code]....
I'm aware of the flaws here, but this is the best I can do so far. How can I get the if test to use A[k] next, as A[k] will always be the biggest value?
I was assigned to create a program that has a 10 x 8 two dimensional array and fill it with random numbers in the range 50 to 70 inclusively.( Got That part down). The second part is to make function named findSmallest that will find and print, appropriately labeled, the smallest number in the array.
I cant seem to get it working. The code for finding the smallest give me some weird number
Here my Code:
//Assignment 18 Program 2 #include <iostream> using namespace std;
Above you said to find the middle value you should divide the array by two and then display the middle value (aka the median). For example, for an array consisting of 1 2 3 4 5, 3 would be the middle value.
My question is, how/what do I write to tell the program to display the middle value???
So far, I have done enough research and written enough code to receive values from the user and sort the array in ascending order. I simply don't know where to go from here (I started C++ about 1 month ago). I don't know how to tell it to pull the middle value.
I've researched "find_if", "nth_value" and a boat load of others with no luck
I keep getting an unresolved external symbol error in the double GetHighest function. Ive looked over the code many times and can figure out why its giving me this error.
//Question 1
// Copy source code below and save to a .cpp file (say lab11_01.cpp) and write statements to print what is indicated in the source code. //In this question, you will implement code for finding the highest value in an array, and you do this in a function. //This program gets a series of test scores and calculates and display the highest score.
#include <iostream> #include <iostream> #include <iomanip> using namespace std; // Function prototypes void getTestScores(double[], int); double getHighest(const double[], int);
I want to find third largest character in ascii as alphanumeritic. The problem is i cannot use arrays. How can I find third largest number ? Have to I compare all chars with each other ?
With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".
This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0. nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....
for (n=0; n<sizeof(digits)/sizeof(int); n++) { if(repCount<2) { // nonRepCount=0; for (o=n+1; o<sizeof(digits)/sizeof(int); o++)
I'm trying to write a program where in you input 9 numbers from 1-10, then it determines the missing number. Here's my code. It has a lot of errors. I want to improve it by setting conditions like no repetition/ 0< number <10.
#include <iostream> using namespace std; int main() { int d[]={1,2,3,4,5,6,1,7,9, 10}; int i=0,j=0,c=0,missing=0; for (i = 0; i < 9; i++)
[Code] ....
I'm so new to C++. It always prints out the number 10 even though I typed it already. How to determine the missing one.
This is for a 2-d array, but if i understand how to do it for a 1-d array, I can do it for a 2-d. So to keep it simpler, I will just pretend its for a 1-d array. I am working on a project where i must enter the month number of a storm and then tell the user which month had the most storms. So I have an array and the user determines the size of it by entering the number of storms. Then, using a for loop, the user enters the month number for each storm and the data is used to fill the array. This is to be used in a part of a much larger piece of code. I made a sample code below to mimic what i want to do:
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
How should I go about finding the 2nd, or 3rd smallest element in an array? Where the minimum is not equals to the next minimum.
Here is the psuedocode I've found
void Min(A[i..j], int&min, int &next_min) if (i=j) then min=A[i] and next_min = infinity else mid = (i+j)/2 Min(A[i to mid]),a,b) Min(A[mid+1 to j],c,d)
Let min be minimum among a,b,c,d
Let next_min be the next_min among a,b,c,d
min != next_min
Here is what I wrote but it does not seem to work.
#include<iostream> #include<vector> #include <cstdlib> using namespace std; void minfind(vector<int> &array,int left,int right, int &min, int &next_min);
I am trying to find the size of an array using a Try-Catch block. As seen on the code, I want the error to be caught when the index is out of range in "while" loop but at each time, program stops working.
int x[] = {34,5,1,536,2}; int length = 0; int tt = 0; try {
I have a specific byte (that is unsigned char) array, that I need to find in a very big file (2GB or so), currently I'm using:
size_t fsFind(FILE* device, byte* data, size_t size) { int SIZE = (1024 > size) ? 1024 : size; byte buffer[SIZE]; int pos = 0; int loc = ftell(device);
[Code] ....
Which seems to find proper result on first use, but on subsequent searches it seems to find invalid positions, is there something I'm doing wrong, or is there a better way?