C :: Implementation Of Histogram Using Functions And Arrays

Apr 12, 2013

I'm trying to code one of the problems but it really is hard to catch errors for a novice like me at first.

I have to Write a single C function for computing the histogram of a list of nonnegative integers into 4 bins.

The main() function first initializes a positive integer array called List of size N, takes 3 inputs from the user A, B, C (assume 0 < A < B < C), and declares a second integer array Bin[4].

The doBinning function should count the number of elements of List in the interval [0, A) and store it in Bin[0], count of [A, B) in Bin[1], count of elements in [B,C) in Bin[2], and the number of elements >= C in Bin[3]

Code:
#include <stdio.h>
#define N 10
#define M 4
int *doBinning (int source[], int dest[], int a, int b, int c);
int main (){

[Code] ....

Somehow I keep getting error from ptr = doBinning(List[], Bins[]. What am I doing wrong? Code might contain some errors.

View 3 Replies


ADVERTISEMENT

C :: Stack Implementation Using Arrays

May 31, 2014

Code:

#include <stdio.h>#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 100
struct stackk
{
int top;
int items[STACKSIZE];
};
typedef struct stackk *s;

[Code]...

View 1 Replies View Related

C :: How To Pass Arrays To Functions

Sep 23, 2014

I have read about it in my book and also on this website but i still have things uncleared....

View 11 Replies View Related

C :: How To Create Functions With Arrays

Jun 12, 2013

how to create functions with arrays :/

You have to write a single C program that creates a one dimensional array of size MAX(to be declared as a declarative constant using directive #define MAX 10), initializes its elements with a given value using the function InitArray, then populate the array with some random numbers between 1 and MAX inclusive, and finally search the array for certain keys.

The structure for this C program is as follows:

int main() {
//array A to be locally declared here
int
size = MAX;
}

[code]....

View 3 Replies View Related

C :: Passing Arrays Into Functions

Nov 4, 2013

i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.

Code:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}

[code]....

View 2 Replies View Related

C# :: Arrays In Functions And Variables

May 21, 2014

I'm truing to write a function that gets an array of arrays, and returns an array. I placed the code I'm using below, but I'm getting all kinds of errors. How is the right way to do this?

static void Main(string[] args) {
int[] draw1 = new int[] { 5, 8, 3 };
int[] draw2 = new int[] { 3, 6, 8 };
int[] draw3 = new int[] { 6, 7, 9 };
int[] draw4 = new int[] { 5, 6, 0 };

[Code] .....

View 4 Replies View Related

C/C++ :: How To Use 3 Functions To Sort 9 Arrays

Mar 31, 2015

I can write code that can sort arrays with Bubble, Selection and Insertion algorithms but I'm not sure how to have them be called and return a value 3 different times with 3 different sizes. For example, I need it to return 10, 100 and 1000 but I'm stuck.

#include <stdio.h>
void selectionSort (int list[], int last);
int main()

[Code].....

View 14 Replies View Related

C :: Functions Which Change Arrays Without Pointers?

Jan 17, 2014

the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.

View 9 Replies View Related

C :: Recursive Functions With Arrays As Parameters

Sep 21, 2013

I wrote a fuction in C with the prototype 'void raisePowerOf2(int array[],int pow);'

If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)

But it seems that this function doesn't give the exact answer

And I tried this from java also,with the same implementation.It produced the answer precisely .

I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly

This is the code in c

Code:

#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
int a[2]={1,-1};
raisePowerOf2(a,5);
return 0; }
void raisePowerOf2(int array[],int pow){

[Code]...

This is the code in java....

Code:

public class NewClass4 {
void raisePowerOf2(int array[],int pow){
final int len=array.length;
int store[]=new int[len+1];
int qtnt=0;
for(int i=len-1;i>=0;i--){
store[i+1]=(array[i]*2)%10+qtnt;
qtnt=(array[i]*2)/10;

[Code]...

View 7 Replies View Related

C++ :: Declaring Parallel Arrays As Functions

Oct 23, 2013

i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function?

pointtwod.h
class PointTwoD {
private:
int xcord,ycord;
float civIndex;
LocationData locationdata;

[Code] ....

when i compile the error message i get was even when i i put in int xord[]; in my PointTwoD.h file:

PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'

PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)

PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token

View 1 Replies View Related

C++ :: Using Void Functions To Display Arrays

Nov 8, 2013

I want to write a code that gets three values from the user and puts them into three arrays. When the user enters -999, I want to print out a chart showing all the values they put in. This is what I have so far but it wont build. It tells me std::string is requested, but I'm not sure where to put it, and printArrays is declared void. How can I fix this?

#include <iostream>
#include <string>
using namespace std;
const int ARSIZE = 400;
void printArrays (string reportTitle, int levelsArray[], int scoresArray[], int starsArray[], int i);

[Code] ....

View 2 Replies View Related

C++ :: Passing Structure Arrays To Functions?

Oct 31, 2013

Description: Use functions and structures to simulate storage in a warehouse

*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

[code].....

I keep getting a linker error on every function. what am I doing wrong?

View 2 Replies View Related

C/C++ :: Recursive Functions With Arrays As Parameters

Sep 21, 2013

I wrote a fuction in C with the prototype

'void raisePowerOf2(int array[],int pow);'

If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)

But it seems that this function doesn't give the exact answer

And I tried this from java also,with the same implementation.It produced the answer precisely .

I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly .

This is the code in c

#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
    int a[2]={1,-1};
    raisePowerOf2(a,5);  
    return 0;
}  void raisePowerOf2(int array[],int pow){

[Code] ....

View 5 Replies View Related

C++ :: Passing Char Arrays Between Functions Of Same Class

Nov 16, 2013

I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.

Here's my code:

Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph

[Code] ....

View 4 Replies View Related

C/C++ :: Functions Passing Size Of Arrays As Value Parameters?

Mar 11, 2014

we were given this code:

// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>

[Code]....

or are they referring to something else?

View 4 Replies View Related

C++ :: Globally Declared Arrays Accessed By Multiple Functions

Mar 15, 2013

I currently have globally declared arrays, which are accessed by multiple functions. I want to turn the program so that the arrays are no longer globally declared, but are passed to functions by reference.

I have one problem with passing the arrays: I found that, through debugging, I HAVE TO resize the array when I pass it by reference. For instance, I was using int a[10] when it was globally declared, when it is passed by reference with size 10, it does not work, instead it should be higher than 10 (certain number). Why is this happening? I do not get it...

View 6 Replies View Related

C++ :: Passing / Returning Character And Integer Arrays With Functions

Jun 21, 2013

Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary

View 1 Replies View Related

C :: Number Of Utility Functions For Two Dimensional Arrays Of Integers Or Matrices

Nov 7, 2014

I am working on a number of utility functions for two dimensional arrays of integers, or matrices. However I am having a problem with segmentation faults, most likely due to errors in using malloc in functions like copyMatrix.

Code:
matrix_utils.h~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//This function checks if two matrices are equal
int isEqual(int **A, int **B, int n);

//This function returns one row of a matrix
int * getRow(int **A, int i, int n);

//This function returns one column of a matrix
int * getCol(int **A, int j, int n);

[Code] ....

View 2 Replies View Related

C :: Functions That Declare Arrays In Function Input Even Though Already Declared In Main

Mar 6, 2015

I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?

For example:

int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])
int main(void)

char glosorSv[][MAX]
char glosorEn[][MAX]

View 2 Replies View Related

C :: Borders Around Histogram

Mar 6, 2015

I'm able to get the graph, but now getting the border on the other side of the graph to align it with the right side of my screen.The output looks like that right now because I'm currently playing around with my y axis (right under the for loop) trying to scale everything. I've tried everything many different ways to get this to work.getting the border on the other side of the graph.

Code:

#include<stdio.h>
#include<Windows.h>
int main(void) {
int MAX = 0; //initialize and declare variables
int allcounts [10] = {0}; //store an array of integers for
}

[code]...

View 4 Replies View Related

Visual C++ :: Histogram With Bin Size 5

Mar 15, 2013

I have following code to create histogram, but it gave wrong output. In the program input_vector read 100 double numbers. I want to create a histogram with bin size=5. Output is [0;0;0;0;0].

Code:
vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector) {

long int i;
long int j;

Mat histogram_input(input_vector);
cout<<"Histogram Input Matrix:"<<histogram_input<<endl;
int histSize =5;

[Code] .....

View 4 Replies View Related

C :: Printing Histogram About Number Frequencies?

Mar 6, 2015

have this program .. i tried to make it work to give me this result output:

Code:
input array {1,3,5,1,1,8,6,6,1,3,2,1,6,8,8}
[0]
[1] *****
[2]*

[Code].....

instead i'm having asterisks at the end of the output

View 14 Replies View Related

C :: Generating Histogram Of PGM Format Image

Jul 29, 2014

I need a C code for generating a Histogram with intensities at X-axis and number of pixels at Y-axis from a PGM format image.

View 5 Replies View Related

C :: Scaling Y Axis - Vertical Histogram

Mar 6, 2015

Scaling the yaxis on my histogram for one of my class projects. I've gotten mostly everything but stuck on scaling. I'm pretty sure it's something simple to do, but I'm having trouble, and I've tried everything to my knowledge to get it scaled from 0.1 - 1, like this:

Here is my code:

#include<stdio.h> //include all preprocessor directives
#include<Windows.h>
int main(void) {
int MAX = 0; //initialize and declare variables
int allcounts [10] = {0}; //store an array of integers for
int yaxis, xaxis = 0;

[Code] ....

I'm close, but every time I try and change my y axis in the for loop from 1 going down to 0.1, it doesn't give me a right output.

View 2 Replies View Related

C++ :: How To Create Histogram From A Set Of Values In OpenCV

Mar 9, 2013

I have a text file which consist of several values. These values represent distance from origin to any point in the triangle. How can I create histogram from these values? Is there any functions in OpenCV which can create histogram from these values?

Below my sample values are given:
..........................
3.4 1.2 6.9 0.2 5.1 2.9
........................

View 2 Replies View Related

C :: Normal Distribution Histogram - Random Numbers

Feb 6, 2013

Write a function that generates 1000 normally distributed (Gaussian Probability Distribution) random numbers. Range should be between -3 and +3. Numbers should be double floating point.

There's more to it than that, but I've got it from there.

View 7 Replies View Related







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