Visual C++ :: Printing 2 Arrays With 10 Numbers Per Line

Jan 14, 2014

i got 2 arrays, how would i print 10 numbers per line, so that would be 5 numbers from each array.

array1[40];
array2[40];

array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2

...... and so on

how can i put this in a loop?

and so on but there are 80 elements so i cant go one by one.

View 5 Replies


ADVERTISEMENT

C++ :: Printing 10 Numbers Per Line?

Nov 3, 2013

I'm working on a program that prints every even number from 100 to 200. How i would be able to print 10 numbers per line?

Code:
#include <iostream>
using namespace std;
int main()
{
int x;
for (x=100; x<=200; x++)
cout <<x++<< endl;
system("pause");
return 0;
}

View 2 Replies View Related

Visual C++ :: Printing Arrays To File In Order

Jan 14, 2014

I have 3 arrays (even, odd and negative), they are all different sizes, but they maximum elements they can have is 50. How do I write them to a file in this format

EVEN ODD NEGATIVE
2 3 -2
4 5 -4
6 7 -9

Code:

size = 50; //they dont all 50, its just that array cant be bigger than 50
for (int i =0; i < size; i++) {
cout <<setw(5);
if (even[i] != 0) {
myfile << eList[i];
myfile << endl;

[Code] .....

View 5 Replies View Related

C :: Assigning Values To Arrays / Printing Arrays

Jul 1, 2014

Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.

I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] .....

View 3 Replies View Related

C++ :: Printing Vector Adding New Line

Oct 10, 2013

I have a vector of structs.

struct myStruct{
string text;
int num;
};

vector<myStruct> foo;

And I am attempting to print the text followed by a space, then the number. Like so:

foobar 5

But when trying to print my vector using

ofstream outputFile;
outputFile.open ("file.txt");
for(int i = 0; i < foo.size(); i++) {
outputFile << foo[x].text << " " << foo[x].num << endl;
}

It prints like

foobar
5
moretext
8

With an extra newline and space. How to get rid of it and print it on the same line.

I have checked that text does not include new line character at the end. Also, it seems to print correctly using cout, but not print correctly to output file...

View 1 Replies View Related

C# :: Printing All Values Above The Diagonal Line In 2D Array

Apr 11, 2014

I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:

{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}

I'd have to print the elements in italics. I've tried this:

for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}

with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.

View 2 Replies View Related

C :: Printing Matrices Without Arrays

Nov 13, 2013

Any example code for printing a square matrix without arrays?

View 7 Replies View Related

C++ :: Printing Arrays In Columns

Jun 25, 2013

I'm working with arrays and I get them column by column and need to print them. I as there a way to print in columns?

For example: I produce an array of A, B and C from a loop and then need to print them in one column and the go to the next column ....

so in the end I shall have an output like this:

A E
B F
C G
D h
... ...

My arrays are too long (over 50K) so I cant just store the arrays and then print them. I need to produce each column array, print them and delete it and go to the next column.

View 1 Replies View Related

C/C++ :: Printing Arrays In Structures?

Mar 1, 2014

# include <conio.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>

[Code]....

I tired changing the conditions in the for loops, but then I end up entering information multiple times and I want that to be the user's option. Do I have to change the for loops or something else? I've tried everything to get what I want but nothing works. When I print the receipt, only the last food Item that I entered prints.

View 14 Replies View Related

C++ :: Printing Chinese / Unicode Characters To Line Printer Using WritePrinter Method?

Jul 10, 2013

I'm trying to print Chinese/unicode characters to a line printer(EPSON LQ-2090) using the writePrinter method in c++.

ANSI characters print fine, but when I throw the buffer of widechar Chinese characters at it, they come out like garbage/ANSI chars.

while debuging string shows chinese characters but in memory it shows ANSI characters not chinese and these ANSI characters are get printed on printer.

Note that if I change the DocInfo datatype parameter to "TEXT" instead of "RAW" then also the Chinese characters donot print.

Is there a way to get Chinese or unicode characters to print correctly?

View 6 Replies View Related

Visual C++ :: Line Graph Using Single Line Values From Bitmap

Feb 3, 2014

I was loaded a bmp file in my mfc window and stored rgb data in a file.My image size is 320x240.

Is possible to pick a single point (location) from that bmp image (Not the whole window)?

i like to plot a line graph using the pointed single line data using the stored file data?

here R is X Axis and G & B is Y Axis.

If i have 2D array of data means how can i plot the line graph?

View 4 Replies View Related

C++ :: Dealing With Dynamic Arrays - Printing Initialized Objects

Jul 15, 2013

I have a problem in dealing with dynamic arrays. I have initialized the objects and now i want to print them.

Code: // main
char* namesList[] = {"Brad Shaw","Aimen Adams","Sal Dimitry","Cristi Anreaz","Poala James"};
int idList[]={232,444,135,52,134};
Team t1( namesList,idList,5,"waqas");
t1.Print_team(); My class Team looks something like this:

[Code] ....

The print function does not work. I have to implement the print function without taking any parameters.. How should i do that ?

View 9 Replies View Related

C++ :: Printing Unspecified Set Of Numbers?

May 8, 2014

how are we able to print out a random number (after using srand() and rand() ) - where you there is an unspecified amount of variables given. So, if the user selects yes to have another number given, how are we able to show the previous numbers and the current one?

View 1 Replies View Related

C :: Printing 21 Different Numbers That Are Randomly Generated?

Mar 2, 2014

The program is supposed to be printing 21 different numbers that are randomly generated. Why am I getting the same number 21 times? Using dev C++ compiler.

Code:

/*prints random numbers between 1 - 99*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code]......

View 3 Replies View Related

C++ :: Printing Even And Odd Numbers In Alternating Pattern?

Nov 23, 2014

We never really had a thorough discussion yet about if-else statements and while.. but our teacher already gave us a difficult assignment..

We should write a program the accepts a number , n, and displays the first n values of the number series:

the pattern to be print was like this 1 1 2 3 4 5 8 7 16 9 32 11 64 13...

alternating odd and even numbers using while and if-else statements

if you input n, the output will print only until 1 1 2 3 4 5 8 7

View 2 Replies View Related

C++ :: Printing Square Free Numbers?

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.

A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"

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

[Code]........

View 1 Replies View Related

C/C++ :: Printing Square Free Numbers

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.

The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.

A square-free number is a number that is not evenly divisible by the square of any prime number ....

#include <iostream>
#include <vector>
using namespace std;
bool noSquare (int num); //Function to determine if the number is square-free
vector<int> getPrimes(int num); //Function to get a vector of all primes below num
bool isPrime (int number); //Function to determine if individual numbers are prime
int main()

[Code]...

By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.

View 3 Replies View Related

C++ :: Printing The First N Prime Numbers (user Input)

Jan 15, 2014

//Finding prime numbers
#include <iostream>
using namespace std;

[Code]....

/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.

View 1 Replies View Related

C# :: Add Line Numbers To A Text Editor

Jun 7, 2012

I'm trying to add line numbers to a text editor I'm building but not having much luck. I'm trying to find a way around building something massive with a picture box next to my textbox etc. I'm tried adding VS Basic to my references and searching for the linenum_rtf.cs but I can't seem to find it under existing items.

View 4 Replies View Related

C++ :: Big Numbers In Arrays

Apr 17, 2014

I have to create three arrays. my first array is going to be a 20 digit number if not less. this also goes for my second array.

#include <iostream>
const int Size = 20;
int CreateArrays (int Digit, int DigitArray[Size]);
void DisplayArrayEquation ( int Array1[Size], int Array2[Size], int ArraySum[Size]);
using namespace std;
int main(){
int Digit1, Digit2, DigitSum;

[Code] ......

View 17 Replies View Related

C :: Print Listing With Line Numbers - Cannot Execute / Run Program

Feb 18, 2013

The problem is with the first "Type and Run," where the code looks like this:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] ....

I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:

Code:
print_it.c: In function "main":
print_it.c:36:15: error: "stdprn" undeclared (first use in this function)
print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in
print_it.c: In function "do_heading":
print_it.c:49:16: error: "stdprn" undeclared (first use in this function)

I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] .....

It compiled OK with the gcc compiler but I only get this when I run the program:

Code:
Proper Usage is:
print_it filename.ext

I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.

Questions:

1. What should be done to make this program run?
2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?

View 6 Replies View Related

C :: Read 15 Numbers And Display Each Number On Separate Line

Oct 21, 2014

Program to read in 15 numbers and display them as follows //each number on a separate line

Code:

# include <stdio.h>
# define MY_ARRAY 15
int main(){
int i ;
printf("please enter 15 numbers

[Code] ....

Error that i get from compiler:
Error E2062 array1.c 14: Invalid indirection in function main()
Error E2062 array1.c 19: Invalid indirection in function main()
both pointing to the separate "scanf"

View 6 Replies View Related

C++ :: Reading Group Of Numbers Per Line In Text File

Mar 27, 2013

I am working on a project for school that has us read in a text file that contains 8 lines of SSN and grades. I am not sure how to go about reading in the lines and differentiate between the SSN and grades in the calculations.

View 1 Replies View Related

C :: Prime Numbers And Arrays

May 27, 2013

I was going through a book I have about C trying to learn about arrays, and one of the first few examples of what could been done with an array was showing how to use an array to generate a list of prime numbers. I've been staring at this program for about an hour trying to understand how it works (it does), but the workings of one for loop within the program.

Code:

#include <stdio.h>
#include <stdbool.h>
int main () {
int p, i, primes[50], primeIndex = 2;
bool isPrime;

[Code]...

So that is saying in order for this loop to go on, really two conditions must be met since there's that && operator. isPrime must be true (I think that's what it means by just having "isPrime" and not setting it equal to anything) and p / primes[i] must be greater than or equal to primes[i].So at the beginning of the loop, since i = 1, p = 5 (as per surrounding loop), and prime[i] = 3 ( as per the variable assignment at the beginning of the program ), the loop condition would be "isPrime && 5 / 3 >= 3"

"5 / 3 >= 3" The loop should stop right there! 1.666666667 is NOT greater than or equal to 3!

View 14 Replies View Related

C :: Add Two Big Integer Numbers Without Use Of Arrays

Dec 1, 2014

i'm having difficulty with a problem, i need to add two big numbers suchas 54646774456776 and another one 445556777554 and it would print the result. how can i approach this problem without the use of arrays?

View 4 Replies View Related

C++ :: Arrays Getting Random Numbers

Oct 30, 2013

Ok so Im suppose to make this program were the user inputs the size of the array then the user sets a certain range min and max for random numbers to be generated. I have a function named fillarray()

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int fillarray();

[Code] ....

Whenever i run the program i keep on getting a loop for the size of the array.

View 1 Replies View Related







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