C++ :: Program To Print Upper Half Of Matrix
Jan 3, 2015
This is a program to print upper half of the matrix.
#include <iostream>
using namespace std;
int upperhalf(int n, int apu[n][n]) {
cout<<"The upper half of the matrix is :
[Code] ....
the compiler is giving these errors:-
sh-4.2# g++ -o main *.cpp
main.cpp:4:31: error: use of parameter outside fun
ction body before ']' token
int upperhalf(int n, int apu[n][n])
[Code] ....
I dont know where i am wrong.
View 3 Replies
ADVERTISEMENT
Jan 27, 2015
I wants to print matrix such that Consider that original matrix look like following
1 2 3
4 5 6
7 8 9
Now I want to print like following
7 8 9
4 5 6
1 2 3
we can use only two for loops.
View 1 Replies
View Related
Nov 9, 2014
Essentially what I need to do is take a text file, ("input.txt"):
4 4
1 0 0 1
1 1 1 1
0 0 1 0
0 0 1 0
And take the first two values on line 1 (4, 4) and use them as length and width.
Number of rows: 4
Number of columns: 4
Then I need to print out the matrix and further manipulate it. I need to find the sum of the 1's per column and then take that number and replace each 1 with the 1's in each column.
So it'll look like this:
2 0 0 2
2 1 3 2
0 0 3 0
0 0 3 0
The part that's mostly troubling me is that my instructor will be giving me the input file with random values, so I don't know what the matrix dimensions will be.
I can read the 2D array but can't seem to use it after. I need to find a way to skip the first line, and then read in the matrix and be able to use it mathematically to add up each column.
View 1 Replies
View Related
Feb 11, 2014
I am trying to create a random 3x3 matrix and print it out in a text file using basic functions. My code below will not compile.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//nxn Matrix = 3x3
const int ROWS = 3;
const int COLS = 3;
[Code] .....
View 2 Replies
View Related
Jan 16, 2014
whats wrong with this code, I'm trying to parse a .js file and replace all the ";" with "; " i.e add a new line after each ";". So I load the file into a char[] buffer then assign a string to this contents of this buffer. Then loop char by char through using an iterator and check for a ";", if found use replace. So int i gets to about 85898 then crashes with unknown error, 'i' should reach about 175653. It does work up till it crashes. And, is this not a simpler way to load a file into a buffer, there is in C.
Code:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
int main()
[code]....
View 8 Replies
View Related
May 9, 2013
how to display the other half of the box's border? where should i put the printf? or is there any other method that you can show me using arrays?
Code:
#include <stdio.h>
#define ROW 15
#define COLUMN 15
void disp_box (char b[ROW][COLUMN])
[Code].....
View 9 Replies
View Related
Nov 11, 2013
For example if we have 101010 First half is 101 which you get by multiplying 101010 * 10 ^-3
now how do you get the second half (010) ??
View 2 Replies
View Related
Mar 9, 2014
How do I round to the nearest half integer?
Example;
0 to 0.2 = 0
0.3 to 0.5 = 0.5
0.6-0.9 = 1
What's the formula for C++?
I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?
For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2.
8.4 * 2 = 16.8
16.8 + .5 = 17.3
17.3 - decimal = 17
17/2 = 8.5
I want to do something like;
cout << " Half number: << (x*2+.5)remove decimal/2 << endl;
What would I have to put in place of "remove decimal"?
View 4 Replies
View Related
Jan 31, 2015
was making a somewhat of a Binary to Hex convertor but only 10/15 cases work and the non working are in the middle; 0010, 0011, 0100, 0101, 0110, 0111;;
// Test Code.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main(void)
{int A;
cout << "Enter the binary starting with the MSB
[code]....
View 5 Replies
View Related
Sep 24, 2013
The output should be something like:
5
45
543
5432
54321
View 2 Replies
View Related
Mar 11, 2013
I am trying solve this a problem: [URL] .....
In short:
1. Input is an N x N grid with a non-negative integer in each cell.
2. We can move from one cell to any of its adjacent cell in all four directions.
3. The 'cost' needed to move from one cell to another is the positive difference of their values.
4. We have to find the minimum cost such that we can visit atleast half of the cells with that cost;
I am not being able to think of any solution that runs in time O(N2) or better (N2 because of the size of N, any algorithm worse than it will not run within the time limit) for this problem.
So I need a hint on how to solve this problem optimally.
View 2 Replies
View Related
Oct 9, 2013
I just started Linear Algebra for my programming degree and to full understand everything I want to put it into code and make my own "matrix calculator." I have all the theory but I am having issues keeping the matrix variable and moving it around the class' functions to create it and output it. Once I know I have it saved I think I can get the addition/multiplication to work. Here is the code I have so far:
#include <string>
#include <iostream>
using namespace std;
class matrix {
[Code] ....
View 5 Replies
View Related
Apr 23, 2014
Im using apmatrix and im inputting values into a 4 by 4 matrix and im getting all these errors that have nothing to do with my cpp file so im guessing its apmatrixies fault. Also I put in the cpp and header file of both apmatrix and apvector into my project folder. Heres my code:
// Libraries
#include "apmatrix.h"
#include <iostream>
//cout, standard output
// <<, stream insertion operator
[code]....
My errors are:
error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.c:program filesmicrosoft visual studio 11.0vcincludexkeycheck.h2421TheMatrix
4IntelliSense: identifier "EMIT" is undefinedc:Program FilesMicrosoft Visual Studio 11.0VCincludeyvals.h4911TheMatrix
and a bunch are repeated
View 1 Replies
View Related
Apr 3, 2014
I write this code for Inverse of matrix in C language . But there is error in determinant function that say "can not convert 'float' to 'float(*)[20]' for argument '1' to 'float determinant(float(*)[20])' " ....
/* a program to calculate inverse of matrix (n*n)*/
//actually one of the way to calculate inverse of matrix is : A^(-1) = 1/|A| * C(t)
that A is matrix and c(t) is taranahade A
#include <stdio.h>;
#include <conio.h>;
#include <string.h>;
#include <stdlib.h>;
const int max=20;
int i , j , n , k , size=0 , row , column ;
float num , det=0 , inverse_matrix[max][max] , matrix[max][max] , new_mat[max][max] , m_minor[max][max] , m_Transpose[max][max];
[Code] .....
View 14 Replies
View Related
Oct 2, 2013
I can get the first letter to change if there is only one word. But if there are two words it wont change and display the second word's first letter and I'm not sure why.
#include <iostream>
#include <iomanip>
#include <cstring>
[Code].....
View 3 Replies
View Related
Mar 24, 2013
I want to find transpos of square matrix.but my program does not run complete.
Code:
#include<iostream>
using namespace std;
const int size=3;
void read(int a[size][size])
[Code] .....
View 2 Replies
View Related
Mar 9, 2014
I have a program matrix multiplication but it work not for big arrays. n should be bis 200.
#include <iostream>
#include <time.h>
#include <cstdlib>
[Code]....
View 6 Replies
View Related
Nov 18, 2014
I'm not sure why Im getting a wrong Sum. of the Columns.
Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:
double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)
Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:
Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0
#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;
[Code].....
View 1 Replies
View Related
Mar 27, 2013
i want to know how i can solve this question? do i need to create a class or write the program codes.
View 12 Replies
View Related
Jul 7, 2014
can i do in this way to check if letter is upper case or lower case is it better to using casting or i can do without casting.
Code:
if(selectOption == (char)81){
selectOption = (char)113;
}
View 2 Replies
View Related
Jul 29, 2013
I have this array (assume sorted) and i need to find out the closest upper value for any input int. Example:
Code:
/* bsearch example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* qsort, bsearch, NULL */
int compareints (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
[Code] ....
So whenever i hit something that is not in the array i would like to know the closes upper value. So for 4 closest upper value is 5, then for 8 it is 12 , for 35 it is 44. how would one do this?
View 1 Replies
View Related
Feb 23, 2015
Write a program that reads characters from the keyboard using the getch() function. All lower case letters will be converted to upper case and printed out to the display using the putchar() function. All uppercase letters will be printed using putchar(). All individual digits will be accumulated and the sum will be printed at the end of the program using printf(). You will write a function to return the upper case of the letter and a second function which receives the current sum and the character digit.
The convert digit function will convert the character digit to a decimal value and accumulate the digit to the sum returning the new sum. Only the letters will be printed out nothing else. The program will continue until the return is received at which time the sum of the digits will be printed on the next line. What was entered: a9 wF23’;/4i What the line actually shows: aA9wWFiI The sum of the digits is: 18
I dont understand why it expects more () in the functions....
View 11 Replies
View Related
Jan 29, 2013
Basically I am to create a program that will read two saved text files; one is [2x4] ~ (matrixA.txt) and another is [4x2] ~ (matrixB.txt). The program is supposed to read both text files, multiply them, and generate an output that will be saved as ~ (matrixC.txt).
So here is my horrible attempt at it:
Code:
#include <stdio.h>
int main() {
FILE * fileA;
FILE * fileB;
FILE * fileC;
[Code] .....
And these are the compile errors...
C:UsersLeDerpHW1.c: In function `main':
HW1.c:27: parse error before `int' //Line 28
C:UsersLeDerpHW1.c: At top level:
HW1.c:34: warning: parameter names (without types) in function declaration //35
HW1.c:34: warning: data definition has no type or storage class //35
HW1.c:35: parse error before `for' //37
[Code] .....
View 13 Replies
View Related
Feb 27, 2013
I made the code that stores and prints 5 row by 5 column values but how to find the largest number from them.What should I do to find the largest number?If I use if-else then it would be very tedious but I think there is way out with for loop but still I can't frame the logic. Here is the code
Code:
#include<stdio.h>
main() {
int lnum[5][5];
int i,j;
for(i=0;i<=4;i++) {
[Code] .....
View 7 Replies
View Related
Jan 7, 2015
After entering the values of the matrix, it is giving me segmentation error. also "if possible", correct it
#include<iostream>
using namespace std;
int main()
{
[Code]......
View 2 Replies
View Related
Jun 1, 2014
I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.
View 1 Replies
View Related