C/C++ :: Write A Program That Adds Numbers To Array

Jan 18, 2015

I am trying to write a program that adds numbers to an array. The array capacity starts out at 2, then doubles whenever the size reaches capacity. The program works perfectly fine when the array needs to be expanded. So I have narrowed down the issues into this one function (_dynArrSetCapacity)

Creates original array
DynArr* createDynArr(int cap) {
assert(cap > 0);
DynArr *r = (DynArr *)malloc(sizeof( DynArr));
assert(r != 0);
initDynArr(r,cap);

[Code]...

If i do createDynArr(10) for instance in the main, the program works perfectly, as it never gets expanded

View 3 Replies


ADVERTISEMENT

C++ :: Program That Asks User For Numbers And Adds Odd Ones Doesn't Work

Nov 12, 2014

Title is self-explanatory.

Code:
#include <iostream>
using namespace std;
int main ( ) {
float number;
float sum;
float divi;
while(number != -1) {

[Code] .....

View 5 Replies View Related

C++ :: Write A Program Which Stores 10 Decimal Numbers In Array

Sep 24, 2014

Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the followings:

Display each elements of the array
Display the sum of all the elements of array

View 4 Replies View Related

C :: Program That Adds All Digits Of Integer

May 5, 2013

Just wanted to share a program I made. It was the answer to one of the end chapter exercises in the C programming book I'm using, asking the reader to create a program that adds all the digits of an integer.

Code:

/* Program to calculate the sum of the digits in an integer */
#include <stdio.h>
int main () {
int number, right_digit, sum = 0;

[code]....

View 7 Replies View Related

C++ :: Program Which Adds Text Onto Image?

Jan 28, 2013

I want to create a program using c++ which will accept text from the user and then adds it onto a image of a form in specific locations (if that makes sense?)

and what libraries will be required?

View 1 Replies View Related

C/C++ :: Write Program Which Find Maximum Among Four Numbers?

Aug 5, 2014

user enter four number and the output will be the greatestt number among these

View 1 Replies View Related

C++ :: Program That Adds Matrices And Edits The Result

Jun 24, 2013

The program adds 2 matrices that are 3x3 using arrays and then stores them into another matrix (array) and then it's edited to show a diagonal line of "0" through it, btw I'm pretty new to programming....

insert
Code:
#include <iostream>
using namespace std;
int main() {
int x[3][3],y[3][3],c[3][3],i,j;
cout<<"Enter your numbers"<<endl;

[Code] .....

It works almost just fine lol, Except that the first portion of the diagonal line does not become zero and instead displays the normal addition result.....

View 5 Replies View Related

C++ :: Program To Merge Numbers In Two Files And Write Results To Third File

Apr 9, 2013

I need to write a program that merges the numbers in two files and writes the results to a third file. The program reads input from two different files and writes the output to a third file. Each input file contains a list of integers in ascending order. After the program is executed, the output file contains the numbers from the two input files in one longer list, also in ascending order. Your program should define a function with three arguments: one for each of the two input file streams and one for the output file stream. The input files should be named numbers1.txt and numbers2.txt, and the output file should be named output.txt.

View 1 Replies View Related

Visual C++ :: Write A Program Where The User Will Input Integer Numbers?

Oct 21, 2014

I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.

Create a dynamic array if the size=2( the initial size must be 2) Repeat until user enters -1.

I have to do this without using vectors.

This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?

Code:
#include <iostream>
using namespace std;
void resize(int *[], int);
int main() {
int *listDyn;
int size=2;

[code].....

View 5 Replies View Related

C/C++ :: Write A Program That Reads Four Float Numbers From The Input Text File

Apr 3, 2015

I need to write a program that reads four float numbers from the input.txt file, then it prints out the greatest of the four numbers into the output.txt file. I did everything, but the numbers don't print out.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;
float number1, number2, number3, number4;

[Code]...

View 2 Replies View Related

C++ :: Write A Source Code That Find Smallest / Largest And Average Of Numbers From Array

May 13, 2014

im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.

void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];

[Code]...

View 5 Replies View Related

C++ :: Write Program That Ask His Or Her Name And Store It In Character Array

May 28, 2013

write a program that ask his or her name and store it in a character array

View 1 Replies View Related

C/C++ :: Program That Adds Feet As Well As Inches And Outputs In Inches?

Apr 4, 2015

This program must take user input(from stdin) that contains both a number and then a punctuation character, either a single quote(') or double quote(") that specifies feet or inches. It keeps prompting the user to enter a length until the user enters the sentinel value of 0. For example:

Enter a measurement and unit: 1'
Enter a measurement and unit: 2"
Enter a measurement and unit: 0
Total: 14 inches

The ultimate goal of this program is to then write an Assembly language program that is structurally similar and makes use of these 4 functions:

void printStr(char *)
Arguments:
edi = address of null-terminated string to print
Returns:
Nothing

[Code] ...

So here is what I have:

int main() {
char value[50];
char *end;
int sum = 0;
long conv;
while(conv !=0)

[Code] .....

I was told to use fgets instead of scanf for for stdin to parse the number and the quotation marks. I think I converted the number from string to integer correctly with strtol, but I really do not know how to obtain the (") or (') from user input so the program knows whether to convert the number to feet or just inches. No matter what I type in, even if it's without a quotation mark, it still multiplies the number by 12. In the IF and ELSE IF statement, it should state

if(value = ''')
and...
else if(value = '"')

View 4 Replies View Related

C/C++ :: Program Which Ask For X Numbers And Store Them In Array

Nov 22, 2014

This is in c. Write a program which asks for X numbers, and stores them in an array.

The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number

Make an array of the indexes where the number was found, and then format your output to match my output.

Sample Run:

How many numbers would you like to enter: 5

Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2

The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4

Press any key to continue . . .

View 10 Replies View Related

C :: Program That Sorts Array Of 5 Integer Numbers

Oct 6, 2013

Write a C program that sorts an unsorted array of 5 integer numbers in ascending order by swapping numbers repeatedly. Specifically, first prompt the user to input 5 numbers and store the numbers in an array. Then, if the numbers in the array are not in ascending order, ask the user to provide the indices of two numbers in the array that the user wants to swap. If the user does not enter valid indices (i.e., outside 0 to4), then re-prompt the user to enter new indices. Continue prompting the user to provide indices of numbers to swap until the array becomes sorted in ascending order. Finally, when the array becomes sorted, the program should print "The array is now sorted in ascending order".

Implementation Requirements

Use the #define directive to define the size of the array.

Implement a function called "checkArrayOrder" to check whether an array is in ascending order or not. The prototype of the function is

"intcheckArrayOrder(int arr[], int size);". The function should return

1 if the array passed to the function is in ascending order0 if the array passed to the function is not in ascending order

Define the function prototype in your program.

Implement a function called "swap", whose prototype is "int swap(int arr[], int size, int i, int j);" which swaps the numbers in positions "i" and "j" of the array passed to the function and returns

1 if the indices"i" and "j" are within bounds (i.e., between 0 and 4) and the swap operation is performed correctly.
0 if the indices"i" and "j" are outside bounds so that the swap operation cannot be performed.

Define the function prototype in your program.

Use the function "checkArrayOrder" whenever your program needs to check whether an array is in ascending order or not; and the function "swap" to swap the numbers the user specifies (Note that, you should check whether the user provided indices are valid inside the function "swap" and not inside "main").

here is my code so far

Code:
#define ARRAY_SIZE 5
void main()
{
int i, array[ARRAY_SIZE];

printf("Enter %d numbers
", ARRAY_SIZE);
for(i=0; i<ARRAY_SIZE; ++i)
scanf("%d", &array[i]);

[Code] .....

I'm just not sure how to proceed. I'm not really sure how to progress the checkArrayOrder function to the swap function (in the if statement).

View 7 Replies View Related

C :: Program That Fills Array With 10 Random Numbers Between 1 And 20

Apr 16, 2013

i have a programming problem and i am unsure of what the final part is.the question is:

Write a program that fills an array with 10 random numbers between 1 and 20, displays the 10 numbers, and finds the sum of the 10 numbers. Call the getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.

i am just really unsure of what this is--getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.what i have got so far is;

Code:

#include <stdio.h>
#include <stdlib.h>
#define ARY_SIZE 10
int main() {
int randomNumbers[ARY_SIZE], sum = 0, i;

[Code]....

View 1 Replies View Related

C++ :: Program To Store 10 Decimal Numbers In Array

Sep 24, 2014

Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:

Display each elements of the array
Display the sum of all the elements of array

View 1 Replies View Related

C++ :: Program That Takes Several Numbers Into Array Into A Function

Nov 25, 2014

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.

View 2 Replies View Related

C++ :: Program To Display All Fibonacci Numbers And 21st Digit Using Array

Mar 7, 2013

Create a program that display all the fibonacci numbers and display the 21st digit using array.

Here's my code:

#include <iostream>
using namespace std;
int main () {
cout<<" This program shows a series of fibonacci numbers
"<<endl;

[Code] ....

View 2 Replies View Related

Visual C++ :: Program Creates A Large Pointer Array Of Numbers

Feb 22, 2013

I am working on a program which creates a large pointer array of numbers and then performs several iterations of operations in them.

Code:
int * u = new int[N];
double * nu = new double[N];
int * nud = new int[N];
for (int i=0;i<M;i++){
for (int i=0;i<N;i++){
u[i]=0;
nu[i]=0;

[Code]...

If M is small enough then there are no problems in the program. However once M is large enough I get the "unhanded exception":

std::bad_alloc at memory location 0x0026f728..

Since I am just reusing the same arrays, and since I am able to make it through a few iterations, I didn't think it could be a memory issue. If it is, is there a way I can clear the data completely after each iteration?

View 4 Replies View Related

C :: Switch Inside A While Loop - Write Min And Max To Get Negative Numbers

Nov 25, 2014

I got the while loop right... but how do i write the minimum and max to get negetive numbers like -88....

Code:
#include <stdio.h>#include <math.h>
#include <conio.h>
int gcd(int, int);
int main() {
int x, y, min, max, result, power, flag = 1;
char c;

[Code] ....

View 6 Replies View Related

C++ :: Getline Function Adds Another Line To Output

Aug 10, 2014

Taken from Accelerated C++ book, I modified those code to use getline() instead of std::cin >> only to find out that the output has extra line. Why is that so?

#include <iostream>
#include <string>
int main() {
std::cout << "What is your name?" << std::endl;
std::string name;

[Code] .....

What is your name?
Naruto
*****************
* *
* Hello, Naruto
*
* *
*****************

Notice one asterisk after the greeting where it should be in the same line as the greeting.

View 4 Replies View Related

Visual C++ :: Fstream Adds Extra Byte?

Feb 7, 2014

I've been having this odd problem when I write a file byte by byte, when I write a byte (dec)10 it adds a (dec)13 in front of it, and as far as I can tell, this is the only byte value that does this.

and most annoyingly, I can't read that (dec)13 with fstream, the only reason I know it's adds it, is because I used an external hex editor.

here is the code that causes the problem:

Code:
#include <fstream>
using namespace std;
int main()
{

[Code]...

but the output file reads '0D 0A' (that's in hex, '13 10' in decimal) when viewed in a hex editor. no other number (that I've tried) adds that extra 13.

View 2 Replies View Related

C++ :: Reading Integers Out Of A Text File And Only Adds Positive Ones?

Sep 26, 2014

I'm basically trying to make a simple program that reads integers out of a text file and only adds the positive ones and not the negatives.

All is well except it won't take the last integer (the last line, I presume.) I took the negative out, nothing to do with that. I put more numbers in and I made the txt file less, no answer. No matter what the last number is, the program won't read it. I've been researching online and I've been seeing that it might be an issue with "while "!inFile.eof())".

Anyway here's the program:

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;

[Code] .....

Here's the txt file:
5
6
-9
21
3

I'm always getting 32 for some reason.

View 2 Replies View Related

C++ :: Tree Arrays Of Same Even Lengths And Adds Values At Odd Indexes

Oct 22, 2013

I am trying a program with that takes tree arrays of same even lengths and adds the values at odd indexes and save at even index of 3rd array and voice versa........

what will be the logic i have tried it a lot of time not worked................

View 3 Replies View Related

C :: Write A Code To Find All The Prime Numbers Before A User Entered Number

Apr 9, 2014

I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.

Code:

#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */

[Code]...

It says the error is on line 23

View 6 Replies View Related







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