C :: How To Find Maximum Value For Middle Row Of Array Data
Aug 2, 2014
I was given some practice problems in my programming class, to prepare for the final and I don't quite understand what this one is asking for exactly:
Write the remainder of the program to find the maximum value for the middle row of the array data. Print the max after finding it. Your code should work for any 2D array of ints with three rows and four columns, so don't hard-code your program to these specific values.
Code:
#include <stdio.h>
int main(void)
{
int data[][4] = {{ 5, 8, 7, 2},
{ 3, 10, 1, 9},
{ 6, 12, 5, 0}};
View 8 Replies
ADVERTISEMENT
Oct 29, 2014
Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.
In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
[Code].....
View 10 Replies
View Related
Mar 12, 2014
I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.
Code:
private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];
[Code] .....
I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this
Code:
int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)
[Code] .....
It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually?
View 8 Replies
View Related
Jan 25, 2014
I'm new to C++ and I'm trying to solve the question but there is just something wrong somewhere.
#include <iostream>
using namespace std;
int main() {
int largest;
int a;
int b;
int c;
cout<< "Enter first value";
[Code] ....
View 1 Replies
View Related
Jul 28, 2014
I have problem with finding the maximum value in a column. This is my code
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
fp = fopen ("C:
ocket1.txt", "r");
float time, altitude, velocity, acceleration, amax, bmax;
[Code] ....
The first loop will print out all of numbers in the velocity column. The second while loop is looking for the maximum value in that column. It is supposed to print out the max velocity in the end of the second loop. However, when I build and run the program, it's crashed. I run debugger and received "Segmentation fault" error. When I eliminate the second loop, it run just fine I use Code::Block for text editor.
View 8 Replies
View Related
Aug 12, 2014
I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case
1. Find the maximum value of the array
2. Find the sum of the first and last element of the array
3. Swap the adjacent pairs of arrays
4. Display the values in array
5. Quit
Please enter choice:
but when i try running the program i did i keep having the break or continue pop up ....
#include <iostream>
using namespace std;
int main() {
int choice;
int number[10] = {2,3,4,5,6,9,10,11,12,99};
[Code] .....
View 6 Replies
View Related
Aug 5, 2014
user enter four number and the output will be the greatestt number among these
View 1 Replies
View Related
Oct 25, 2014
The question is: Write a program that reads 3 integer numbers, then finds and prints the: Mean - Maximum & Second Minimum.
#include <iostream>
using namespace std;
int main () {
double a, b, c;
cout<< "Please enter three values"<<endl;
[Code] .....
View 6 Replies
View Related
Mar 12, 2014
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
Here's what I've done so far:
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
[Code]....
View 3 Replies
View Related
Aug 14, 2013
I want to copy the middle of 2dim array into another array. who knows how i can do it. for example I have:
int A[4][2] = {{1, 2} ,{5, 6} , {7, 8} , {3, 4} };
copy the second and third rows into another array to have the following array:
int B[4][2] = {{null, null} ,{5, 6} , {7, 8} , {null, null} };
View 2 Replies
View Related
Oct 31, 2014
I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...
View 1 Replies
View Related
Dec 6, 2013
I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.
Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();
[Code] ....
View 4 Replies
View Related
Feb 3, 2014
How will you code a program that displays the maximum value in a two dimensional array of integers. the program will ask the user to input the 4x5 array?
i know how to code it. but i dont know what to do to find the maximum value. :( how to find the maximum?
View 4 Replies
View Related
May 22, 2014
i have tried like that int arr[1000000] to initialize but it crashed my programm.but if i do int arr[100000] it works fine..why is that and what is the maximum range of integer array initialization??
View 5 Replies
View Related
Aug 25, 2014
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)
[Code]...
View 11 Replies
View Related
Oct 9, 2014
I'm trying to get correct answers from my exam to study for a midterm:
Write a function that returns the maximum value of an array of doubles.
Declaration:
double maximum(array[],int a_size);
So far I've done:
double maximum(array[], int a_size) {
double maxVal;
maxVal = array[0];
for(int i=1; i < size; i++) {
if(array[i] > max
maxVal=array[i]
}
return maxVal;
}
I just need any corrections.
Second, I need to write a function definition that merges two vectors containing integers, alternating elements from both vectors.
Prototype:
vector<int> merge(const vector<int> a, const vector<int> b);
This is my definition so far:
vector<int>merge(const vector<int> a, const vector<int> b){
vector<int> merged;
for(int i=0; i<a.size+b.size; i++) {
if(flag == true)
merged.push_back(a);
flag = false;
else
merged.push_back(b)
flag = true;}
I think I'm lost in the second part...
View 2 Replies
View Related
Feb 17, 2013
I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist..
Code:
typedef struct node {
char* value;
struct node* next;
}
[code].....
View 4 Replies
View Related
Sep 7, 2012
I want to edit the contents of a file using fstream, but none of the modes in the fstream constructor work for me.
If I use ios::trunc, then the whole file is deleted - but I want to retain the contents and edit it. If I use ios::app, then I can only add data to the end of the file - but I want to edit the data in the middle of the file. If I use ios::ate, then the whole file is deleted again, similar to ios::trunc.
How can I create an fstream object without deleting the contents of the file, whilst still being able to move the pointer arbitrarily around in the file with seekp() (and not just placing it at the end as with ios::app)?
View 3 Replies
View Related
Oct 3, 2014
I want to put number in the center of the rectngle. Nonetheless, one space is residual.
Code:
#include <stdio.h>
nt main(){
int i,j;
int column,row;
int n;
printf("Enter column: ");
scanf("%d",&column);
[Code] .....
View 14 Replies
View Related
Sep 18, 2013
A user enters a query and other users reply to it. But it creates a problem here. After adding queries, if I wish to reply to query in between then it adds a redundant entry in file. 1st entry is the original query without reply and 2nd entry is the same query now with a reply added. I want only 1 entry of the query along with replies.Here is the code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include "var.c"
int check_count();
void add_query();
void add_reply();
}
[code]....
View 9 Replies
View Related
May 1, 2013
I am trying to delete a node from the end of a Linked List but I have some problems. Every node has it's unique code. Here is what I do:
1. Ask the user for the unique code of the node.
2. Ask him if he wants to change the data in it or delete the whole node.
3. If he chooses to delete it, I do this:
//let's say that temp1 points to the node
List *temp2 = temp1;
temp1 = temp1->next;
delete temp2;
And it's just not deleting the node.
View 2 Replies
View Related
Jan 17, 2015
I'm trying to create a program which can pan by keep clicking and move the mouse
1. First, I create a class that inherited from the UserControl Class
public partial class CanvasCtrl : UserControl
protected void OnMiddleMouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Middle) {
[Code] ....
2, Second, I create the void in that class too, and write the code to get it to catch the event
public void MainMouseAction() {
this.MouseClick += new MouseEventHandler(OnMiddleMouseDown);
}
It not work, how to solve this out ?
View 8 Replies
View Related
Jan 24, 2013
I created a structure containing two variables of type char.
i.e. char name[64],char details[128];
And a pointer to structure now when I write this name and details to file and now I want to change the particular name.
i.e. To modify then if the stored file name is greater than the entered name then it is erasing the next record line also I need to allocate some memory.
View 2 Replies
View Related
Aug 13, 2014
How do I compare multiple datas?
I have climate data for 6 months and is trying to find the highest climate month among all 6 months. How do I do that?
View 2 Replies
View Related
Mar 24, 2013
I want a recursive function that returns a pointer pointing to the node which has the minimum data in the binary tree.
That's what I wrote:
struct CP {
int data; // data of the node
CP * left; // pointer to the left subtree
CP * right; // pointer to the right subtree
[Code]....
It can only find one side of the binary tree.
View 8 Replies
View Related
Nov 23, 2013
I program a software to get scores from admin and sort them ascending then show the middle score(if admin enter middle).but when i compile it nothing happen.what should i do?here's code ,i use dev compiler
Code:
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main(int argc, char *argv[]) {
int counter,j,count,counter2,m;
[Code] ....
View 14 Replies
View Related