I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:
#include <iostream>
using namespace std;
int main () {
int n = 2;
int r = 2;
if(n==r)
n++;
r*0;
cout << " n is " << n << endl;
cout << " r is " << r << endl;
}
What am I doing wrong, it should say that "n is 3" and "r is 0".
I want to declare a 2D 4*4 array, and fills the array with the multiplication table of an integer x from the user, for example: x*1,x*2,x*3, ....., x*16 and how to pass that array to a function to print the array and to another function that swaps a column with another column chosen by the user.
I'm trying to solve Project Euler 16 where you have to calculate 2^1000. SO I made a program that would solve multiplying a number b a single digit factor through manual multiplication in a vector, just to test things out.
The problem is when I take things out of main and try to make a separate function, the original number is never multiplied.
Here's my code with functions...
/*Using vectors manually to multiply a number to a positive power.*/ #include <iostream> #include <vector> using namespace std; void print_vector(const vector<int>& v);
[code]....
Here is the other code, not using functions but even if I use an extra for loop to multiply by the same factor several times, it still does the same thing.
/*Using vectors manually to multiply a number by two (or any single digit factor).*/ #include <iostream> #include <vector> using namespace std; void print_vector(const vector<int>& v);
I am trying to read two matrices from individual .txt file, and later trying to multiply them. But I am unable to succeed.
Here is the code.
#include<stdio.h> #include<stdlib.h> #include<stdbool.h> // Here starts the main int main() { // The two input values FILE *inputFile1; FILE *inputFile2;
[Code] .....
I am able to get only the first values as the output. The first matrix is 5x3, and the second one is a 3x3 matrix.
Matrix 1 1 2 3 4 5 6 7 8 9 10 11 12
Matrix 2 1 2 3 4 5 6 7 8 9
The output which I am getting is
Enter File name of matrix #1 - with extention - : matrix1.txt Enter File name of matrix #2 - with extention - : matrix2.txt Rows1 = 1 Cols1 = 2 Rows2 = 1 Cols2 = 2Cant multiply those two matrices
I am writing a brute force implementation of matrix multiplication:
Header file:
vector<vector<int> > matrix_multiplication(vector <vector<int> >& a, vector <vector<int> >& B)/>/>/>;
Source file:
vector<vector<int> > matrix_multiplication(vector <vector<int> >& a, vector <vector<int> >& B)/>/>/>{ int n = a.size(); vector< vector <int> > c (n , vector<int> (n)); for (int i =0 ; i<n ; i++){ for (int j =0 ; j < n ; j++){ for (int k ; k < n ; k++){ c[i][j] = a[i][k] + b[k][j];
[Code] ....
I keep on getting occasional seg faults />/>. I can't see why.