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


ADVERTISEMENT

C/C++ :: 2D Array For Printing Both Diagonal Elements Of Matrix

Jan 31, 2014

what if we want to print both the diagonal elements!!!!

View 1 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/C++ :: Reading From A File Line By Line With No Specified Number Of Values

Apr 12, 2015

Im trying to read from a file, line by line, with no specified number of values in the file. Check out my code:

int main() {
string x;
ifstream fin;
int count = 0;
char ch;
fin.open("CWC_Master.txt");
if(!fin)

[Code] .....

Now, this works great! However, its skipping some lines. And I dont know why. For example: Lets say that the input file is:

superman toy
sm2335
19.99
batman toy
bm5532
25.99
aquaman toy
am6786
26.00

Where it should output the above, instead it outputs every other one. Like:

superman toy
19.99
batman toy
25.99
aquaman toy
26.00

How can I fix my code so that it SIMPLY(i say simply because I am still a beginner coder) can read line by line?

View 7 Replies View Related

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

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

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 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

C++ :: Printing Vector Values Preceded By

Apr 17, 2014

Why does this generate an error:

Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( " " , std::cout ) ); whereas this works fine:
Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( std::cout , " " ) ); I know I can use this instead:
Code: for ( std::vector<double>::iterator it1 = vec.begin( ); it1 != vec.end( ); ++it1 ) std::cout << " " << *it1;

View 5 Replies View Related

C :: Drawing A Box With Coordinates - Printing Between Certain ASCII Values

Sep 23, 2014

The assignment is:

1) Write a program that asks the user for a a single character and two XY coordinates. The two X and two Y values should all be integers between 0 and 50. The character should be a printable ASCII character with values between and including ' !' (ascii value 33) and '~' (ascii value 126).

2) Your program should then draw a rectangle made up of the user selected character where the upper left corner is at X1; Y 1 and the lower right corner is at X2; Y2. Be sure to print the appropriate number of blank lines (having spaces in the blank rows is OK) in the beginning and pad each row of your rectangle with X1 leading spaces.

The Output is supposed to be similar to this:

(X1,Y1) = (0,0) , (X2,Y2) = (4,4), the character = ^

^^^^
^^^^
^^^^
^^^^

What I am having trouble understanding is printing between certain ASCII values (ASCII has never been discussed in class).

Another thing I am having trouble with is the main part of the assignment. From what we are currently discussing is loops and the assignment is covering nested loops. My code looks similar to this:
Code:

#include <stdio.h>
int main (void) {
int X1, Y1, X2, Y2;
char cRec;
printf("Enter a character: ");
scanf("%c", &cRec);

[Code] .....

My thinking on the assignment is that you want the X1 coordinate to increase to the value of X2 (same for Y1 and Y2). Is this thinking wrong?

View 12 Replies View Related

C/C++ :: Reading Hex Values From File And Printing Them In Decimal

Dec 1, 2013

I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.

I already read about strtol but I would prefer reading the hex Value into an integer.

Here is my code so far:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int itrack1[1];
int itrack2[1];

[Code] ....

View 11 Replies View Related

C++ :: Banking System - Searching For And Printing Values From TXT File

Mar 21, 2013

So I'm doing a kind of banking system. Atm I've got the user able to create an account and set the balance of it, which is written to a .txt file. However, I would like the user to be able to enter their account no. and the program to cout the account info on the screen. I will be adding more to the program later, but until I work out how to search for values in a .txt file, and print out values on that line I'm a bit stuck.

Code:
Main.cpp -
#include <iostream>
#include "create_account.h"
#include <fstream>
using namespace std;
int menuin;
int main() {
create_account creataccObj;

[Code] .....

Sample .txt file -

// Account_no - Balance //

1001 140500
1002 150600
1003 18600

View 8 Replies View Related

C++ :: Searching Char By Diagonal Not Only The Main

Mar 6, 2015

I have a problem with searching chars by diagonal not only the main, i have a chars in vector and I need to go though all possibilities (as shown in picture) the word has to be side/2 long so here i have 9, so word has to be 4 chars long how I need to do this?

View 2 Replies View Related

C :: Recursive Function For Diagonal Winnercheck?

Oct 31, 2014

I am trying to learn so much C as possible by my own. I have learned a bit already and made my first game. I made a tictactoe with a 3x3 board that works great. But now i want to make it a NxN-board. But the problem right now is my checkwinner-function. I really don't know how I should check the diagonal for winner in the for loop. Earlier I have checked the diagonal manually like you can see down there.

Code:

for (Row = 0; Row < BOARDSIZE; Row++) {
if ((game[Row][0] == 'X' && game[Row][1] == 'X' && game[Row][2] == 'X') ||
(game[0][Row] == 'X' && game[1][Row] == 'X' && game[2][Row] == 'X') ||
(game[0][0] == 'X' && game[1][1] == 'X' && game[2][2] == 'X') ||
(game[0][2] == 'X' && game[1][1] == 'X' && game[2][0] == 'X'))
return 1;

I think I need two foor-loops in each other too and need to check the spots in the board like 0,0, 0+1,1, 0+2,2. Is that even possible?

View 3 Replies View Related

C++ :: Creating Diagonal Pattern By Given Function

Nov 5, 2013

How to create a diagonal pattern by the given function

void diagonal(int size, char op)

The function takes in 2 arguments, size and op and displays a diagonal line of op char. for example, diagonal (5,#) will produce the following output.

#
#
#
#
#

View 4 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C++ :: Find Biggest Part Of Column Over Diagonal Of Matrix

Jan 23, 2013

How to find the biggest column of the matrix (higher of main diagonal) Here is the draft of code that i desighned/ Of cause it has a several mistake. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

#include<iostream>
#include<conio.h>
#include<time.h>
using namespace std;

[Code]....

View 5 Replies View Related

C++ :: Strings - Read Multiple Values In On A Single Line

Jul 28, 2014

My question is on c++ strings. At the moment my program is reading input in one line at a time after the user presses enter.

I want to read multiple values in on a single line. Example: "apple banana orange end" ... How would I do this?

MAIN Code:
#include "Header.h"
#include "Orange.h"
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

[Code] ......

View 11 Replies View Related

C :: Read From And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables. Let's say my text file contains

AXSYZ3482 Tom 100 112 and my code below here works fine when the lines in the text file is separated by spaces.

Code:

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

Code:

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth.

View 4 Replies View Related

C++ :: Reading From File And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables.

Let's say my text file contains

AXSYZ3482 Tom 100 112

and my code below here works fine when the lines in the text file is separated by spaces.

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?

View 2 Replies View Related

C :: Read A Line From Screen / Takes ASCII Values From Entered Text And Edit It

May 10, 2013

This is a small program that reads a line from the screen, takes the ASCII values from the entered text, and edits it. Next, the ASCII values are reinterpreted (am i misspelling?) as text, and displayed. However, my final output has (allways?) at least 7 characters, even if you enter only one. I'm also trying to accomplish, that the part of the string which isn't filled, will be printed empty. In spaces.

compiled with -std=c99.

Code:
#include <stdio.h>
int main(){
int maxsize;
printf("How long is your message?

[Code] .....

View 6 Replies View Related

C/C++ :: Printing Partitions Of A Number Using Constraint On Number Of Values?

Apr 15, 2014

I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:

"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."

I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.

I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.

View 2 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 Array With A New Value

Nov 21, 2013

I have an array, ary[size+1] and the original values entered and then another value, x, entered. I found the index of x that makes the array nondecreasing order

Code:

void InsertX (int ary[], int size, int x)
{
int i=0;
int j;
int index;
while(ary[i]<x)

[Code]...

But i can't figure out how to print the new array with x in it, using its index

View 6 Replies View Related

C :: Printing A Box Using 2D Array

May 8, 2013

how to print a box using 2d arrrays. i have to create a tetris game which a im stuck at this stage... so far i have tired i can only come out with this..my coding done so far is as follows:

Code:

#include <stdio.h>
#define ROW 15
#define COLUMN 15
void disp_box (char b[ROW][COLUMN])
}

[code]....

View 2 Replies View Related

C++ :: 3 Dimensional Array Printing?

Oct 25, 2013

I want to make a program that asks the user for a message and then print out a large graphic of that message. For example, if the user types "he" I want to print out

H..................H EEEEEEEEE
H..................H E
H..................H E
H..................H E
HHHHHHHHHH EEEEEEEEE
H..................H E
H..................H E
H..................H E
H..................H EEEEEEEEE

(treat the periods as spaces. I only put them there because it wouldn't separate the H's correctly.)

I will loop this to continue until the user types quit.

1. How would I set this up to store the user input characters into an array?

2. How would I print out the stored data in the shape of the word?

View 4 Replies View Related







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