Anonymous
Good morning all
Apk
I have never noticed that
Yeah I found it weird...it seems to be waiting for another input but does not assigns it to anything.
None
Showing us the error might help us further assist you though
include <stdio.h> #include <stdlib.h> int main() { int integer,i, min; printf("Enter expected limit of numbers:\n "); scanf("%d", &integer); for(i=0; i<integer; i++) { printf("Enter integer %d: ",i+1); scanf("%d", &arr[i]); } min=arr[0]; for(i=0; i<integer; i+) { if(min>arr[i]) { min=arr[i]; } printf("\nSmallest integer is: %d",min); return 0; }
Pavel
Where am I wrong?
It seems that you didn't close your curly brackets
Pavel
If you format your code properly, you would notice that
Anonymous
First of all the i+1 why is in the print statement, you have the i++ in the for loop it is not needed elsewhere on the loop because it messes with the position of the numbers in the array. Second there is a missing + on the 2nd for loop. You don't close the the brackets on 2nd for loop
None
Okay let me c...
Murugaa
C:\Users\user\AppData\Local\Temp\ccaVbb9v.o TM.cpp:(.text+0x3e1): undefined reference to `addition(int (*) [10], int (*) [10], int, int, int, int)' C:\Users\user\AppData\Local\Temp\ccaVbb9v.o TM.cpp:(.text+0x41d): undefined reference to `subtraction(int (*) [10], int (*) [10], int, int, int, int)' C:\Users\user\AppData\Local\Temp\ccaVbb9v.o TM.cpp:(.text+0x459): undefined reference to `multiplication(int (*) [10], int (*) [10], int, int, int, int)' C:\Users\user\Documents\collect2.exe [Error] ld returned 1 exit status
None
Wow am impressed... Thank you all...
None
Enter expected limit of numbers: 7 Enter integer 1: 99 Enter integer 2: 78 Enter integer 3: 59 Enter integer 4: 48 Enter integer 5: 94 Enter integer 6: -100 Enter integer 7: 100 Smallest integer is: -100 [Process completed - press Enter]
Anonymous
It has run
Well done :)
Pavel
Can you help me to fix it? Is it possible?
You can post it here using wandbox or pastebin, but I can't guarantee that I can help :)
Murugaa
You can post it here using wandbox or pastebin, but I can't guarantee that I can help :)
#include <iostream> #include <fstream> //including operations.h headerfile which consists addition,subtraction and multiplication function declaration #include"operations.h" using namespace std; //main function int main() { //creating input file stream object ifstream fin; //opening matrix.dat file to read data fin.open("matrix.dat"); //if file does not exists displays no such file and terminates if(!fin) { cout<<"No such file exists"; exit(0); } //declaring m1,n1 ---number of rows and columns of matrix a //m2,n2 ----number of rows and columns of matrix b int m1,n1,m2,n2; //declaring 2D array for matrix a and matrix b int a[10][10],b[10][10]; //reading row and column of first matrix from file "matrix.dat" fin>>m1; fin>>n1; //reading matrix values from file "matrix.dat" for(int i=0;i<m1;i++) for(int j=0;j<n1;j++) fin>>a[i][j]; //reading row and column of second matrix from file "matrix.dat" fin>>m2; fin>>n2; //reading matrix values from file "matrix.dat" for(int i=0;i<m2;i++) for(int j=0;j<n2;j++) fin>>b[i][j]; //displaying matrix a and b cout<<"Matrix 1 read from file:"<<endl; for(int i=0;i<m1;i++) { for(int j=0;j<n1;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"Matrix 2 read from file:"<<endl; for(int i=0;i<m2;i++) { for(int j=0;j<n2;j++) cout<<b[i][j]<<" "; cout<<endl; } int ch; cout<<"What operation do you want to perform?\n1. addition\n2. subtraction\n3. multiplicaiton\n"; cout<<"Enter your choice: "; cin>>ch; //You can select operation what you want to perform switch(ch) { case 1: addition(a,b,m1,n1,m2,n2); break; case 2: subtraction(a,b,m1,n1,m2,n2); break; case 3: multiplication(a,b,m1,n1,m2,n2); break; } return 0; }
Murugaa
#include <iostream> #include <fstream> //including operations.h headerfile which consists addition,subtraction and multiplication function declaration #include"operations.h" using namespace std; //main function int main() { //creating input file stream object ifstream fin; //opening matrix.dat file to read data fin.open("matrix.dat"); //if file does not exists displays no such file and terminates if(!fin) { cout<<"No such file exists"; exit(0); } //declaring m1,n1 ---number of rows and columns of matrix a //m2,n2 ----number of rows and columns of matrix b int m1,n1,m2,n2; //declaring 2D array for matrix a and matrix b int a[10][10],b[10][10]; //reading row and column of first matrix from file "matrix.dat" fin>>m1; fin>>n1; //reading matrix values from file "matrix.dat" for(int i=0;i<m1;i++) for(int j=0;j<n1;j++) fin>>a[i][j]; //reading row and column of second matrix from file "matrix.dat" fin>>m2; fin>>n2; //reading matrix values from file "matrix.dat" for(int i=0;i<m2;i++) for(int j=0;j<n2;j++) fin>>b[i][j]; //displaying matrix a and b cout<<"Matrix 1 read from file:"<<endl; for(int i=0;i<m1;i++) { for(int j=0;j<n1;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"Matrix 2 read from file:"<<endl; for(int i=0;i<m2;i++) { for(int j=0;j<n2;j++) cout<<b[i][j]<<" "; cout<<endl; } int ch; cout<<"What operation do you want to perform?\n1. addition\n2. subtraction\n3. multiplicaiton\n"; cout<<"Enter your choice: "; cin>>ch; //You can select operation what you want to perform switch(ch) { case 1: addition(a,b,m1,n1,m2,n2); break; case 2: subtraction(a,b,m1,n1,m2,n2); break; case 3: multiplication(a,b,m1,n1,m2,n2); break; } return 0; }
Here you go bro.
Kwabena
Please I have c++ quiz Which is coding Please I will need your help when we start the quiz It's like this is my first time of learning c++
Kwabena
I will need your help around 1:55pm Which is the next 3hours
Kwabena
Thanks fam
Kwabena
I will sir
Shahar
C++ I have references to *ascending-sorted* std::vector's of typedef std::pair<K2*, V2*> IntermediatePair; where K2 implements the operator<. My current challenge is: Creating std::vector of std::vector<IntermediatePair>, where each std::vector<IntermediatePair> element contains IntermediatePair`s with identical `K2. Do you have an idea?
Vlad
How to create vector of vectors?
Shahar
yeah, that one
Vlad
You've already done it
Shahar
how to manage this insertion, etc...
Vlad
how to manage this insertion, etc...
What do you need a vector of vectors for?
Shahar
What do you need a vector of vectors for?
It's a matter of some static library I working on
Vlad
If it's going to be a 2d array with fixed row size I'd suggest to reconsider
Shahar
That's part of the API
Vlad
That's part of the API
Your API or someone else's?
Shahar
it's about MapReduce API
Shahar
part of university work
Vlad
Can you populate a vector?
Shahar
I have to populate this vector of vectors
Vlad
Now do the same shit but split it into N operations
Vlad
On the beginning of each operation push back a new vector into the vector of vectors
Vlad
Then just do vec2d[i].push_back
Shahar
Suppose we have these vectors: 1, 1, 2, 2, 3, 4, 4 2, 3, 5, 5 So we have to create this vector of vectors [ [4,4], [3,3], [2,2,2], [1,1] ]
Shahar
i don't think your suggestion holds for that need
Vlad
You can just compare current element to the last one. So you know when to switch a vector
Shahar
It's too much of a high level explanation for me
Shahar
The general idea of doing it is a bit clear, but the implementation details here are evil
Vlad
It ain't a rocket science. And I've given you the algo. It's like 5 lines of code. Just code it yourself bruh. Don't make us embarrassed
Shahar
void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase { // std::vector<std::vector<std::pair<K2*, V2*>>> auto shuffledQueue = currentJobContext_.getShuffledQueue(); for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i) { // here we access all threads' intermediate vectors // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); // here we want to insert to shuffledQueue elements of type // std::vector<std::pair<K2*, V2*>> whose K2 is identical } } // else => you aren't thread-0, so go wait on barrier }
Shahar
So just sort then push back same elements
Here you see a skeleton for this function. I'm not sure what you meant to sort
Vlad
You push into the vector from multiple threads?
Vlad
Are you sure that it's a good idea tho?
Shahar
You push into the vector from multiple threads?
This function is executed by only one thread.
Murugaa
#include <iostream> #include <fstream> //including operations.h headerfile which consists addition,subtraction and multiplication function declaration #include"operations.h" using namespace std; //main function int main() { //creating input file stream object ifstream fin; //opening matrix.dat file to read data fin.open("matrix.dat"); //if file does not exists displays no such file and terminates if(!fin) { cout<<"No such file exists"; exit(0); } //declaring m1,n1 ---number of rows and columns of matrix a //m2,n2 ----number of rows and columns of matrix b int m1,n1,m2,n2; //declaring 2D array for matrix a and matrix b int a[10][10],b[10][10]; //reading row and column of first matrix from file "matrix.dat" fin>>m1; fin>>n1; //reading matrix values from file "matrix.dat" for(int i=0;i<m1;i++) for(int j=0;j<n1;j++) fin>>a[i][j]; //reading row and column of second matrix from file "matrix.dat" fin>>m2; fin>>n2; //reading matrix values from file "matrix.dat" for(int i=0;i<m2;i++) for(int j=0;j<n2;j++) fin>>b[i][j]; //displaying matrix a and b cout<<"Matrix 1 read from file:"<<endl; for(int i=0;i<m1;i++) { for(int j=0;j<n1;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"Matrix 2 read from file:"<<endl; for(int i=0;i<m2;i++) { for(int j=0;j<n2;j++) cout<<b[i][j]<<" "; cout<<endl; } int ch; cout<<"What operation do you want to perform?\n1. addition\n2. subtraction\n3. multiplicaiton\n"; cout<<"Enter your choice: "; cin>>ch; //You can select operation what you want to perform switch(ch) { case 1: addition(a,b,m1,n1,m2,n2); break; case 2: subtraction(a,b,m1,n1,m2,n2); break; case 3: multiplication(a,b,m1,n1,m2,n2); break; } return 0; }
Anyone know??
Murugaa
#include <iostream> #include <fstream> //including operations.h headerfile which consists addition,subtraction and multiplication function declaration #include"operations.h" using namespace std; //main function int main() { //creating input file stream object ifstream fin; //opening matrix.dat file to read data fin.open("matrix.dat"); //if file does not exists displays no such file and terminates if(!fin) { cout<<"No such file exists"; exit(0); } //declaring m1,n1 ---number of rows and columns of matrix a //m2,n2 ----number of rows and columns of matrix b int m1,n1,m2,n2; //declaring 2D array for matrix a and matrix b int a[10][10],b[10][10]; //reading row and column of first matrix from file "matrix.dat" fin>>m1; fin>>n1; //reading matrix values from file "matrix.dat" for(int i=0;i<m1;i++) for(int j=0;j<n1;j++) fin>>a[i][j]; //reading row and column of second matrix from file "matrix.dat" fin>>m2; fin>>n2; //reading matrix values from file "matrix.dat" for(int i=0;i<m2;i++) for(int j=0;j<n2;j++) fin>>b[i][j]; //displaying matrix a and b cout<<"Matrix 1 read from file:"<<endl; for(int i=0;i<m1;i++) { for(int j=0;j<n1;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"Matrix 2 read from file:"<<endl; for(int i=0;i<m2;i++) { for(int j=0;j<n2;j++) cout<<b[i][j]<<" "; cout<<endl; } int ch; cout<<"What operation do you want to perform?\n1. addition\n2. subtraction\n3. multiplicaiton\n"; cout<<"Enter your choice: "; cin>>ch; //You can select operation what you want to perform switch(ch) { case 1: addition(a,b,m1,n1,m2,n2); break; case 2: subtraction(a,b,m1,n1,m2,n2); break; case 3: multiplication(a,b,m1,n1,m2,n2); break; } return 0; }
Can someone help me😭😭
Vlad
This function is executed by only one thread.
I thought of something like: using vec = std::vector; using elem_type = pair<int, int>; // can be whatever vec<elem_type> input; std::sort(input.begin(), input.end()): vec<vec<elem_type>> vec2d; vec2d.push_back({}); const elem_type& lastval = input[0]; vec<elem_type>* current = nullptr; for(const auto& elem : input) { if(elem != lastval) { vec2d.push_back({}); current = &vec2d.back(); } current->push_back(elem); lastval = elem; }
Pavel
#include <iostream> #include <fstream> //including operations.h headerfile which consists addition,subtraction and multiplication function declaration #include"operations.h" using namespace std; //main function int main() { //creating input file stream object ifstream fin; //opening matrix.dat file to read data fin.open("matrix.dat"); //if file does not exists displays no such file and terminates if(!fin) { cout<<"No such file exists"; exit(0); } //declaring m1,n1 ---number of rows and columns of matrix a //m2,n2 ----number of rows and columns of matrix b int m1,n1,m2,n2; //declaring 2D array for matrix a and matrix b int a[10][10],b[10][10]; //reading row and column of first matrix from file "matrix.dat" fin>>m1; fin>>n1; //reading matrix values from file "matrix.dat" for(int i=0;i<m1;i++) for(int j=0;j<n1;j++) fin>>a[i][j]; //reading row and column of second matrix from file "matrix.dat" fin>>m2; fin>>n2; //reading matrix values from file "matrix.dat" for(int i=0;i<m2;i++) for(int j=0;j<n2;j++) fin>>b[i][j]; //displaying matrix a and b cout<<"Matrix 1 read from file:"<<endl; for(int i=0;i<m1;i++) { for(int j=0;j<n1;j++) cout<<a[i][j]<<" "; cout<<endl; } cout<<"Matrix 2 read from file:"<<endl; for(int i=0;i<m2;i++) { for(int j=0;j<n2;j++) cout<<b[i][j]<<" "; cout<<endl; } int ch; cout<<"What operation do you want to perform?\n1. addition\n2. subtraction\n3. multiplicaiton\n"; cout<<"Enter your choice: "; cin>>ch; //You can select operation what you want to perform switch(ch) { case 1: addition(a,b,m1,n1,m2,n2); break; case 2: subtraction(a,b,m1,n1,m2,n2); break; case 3: multiplication(a,b,m1,n1,m2,n2); break; } return 0; }
That's not the whole code the issue is probably not here, you can use wandbox.org, it's an online compiler with multiple files support, you can copy content of your files there, press Run, then Share, then copy the URL and paste here
Vlad
cppreference says otherwise
Pavel
ah wait
Vlad
https://en.cppreference.com/w/cpp/utility/pair/operator_cmp
Vlad
Until c++14 it wasn't constexpr
Shahar
Until c++14 it wasn't constexpr
Ah okay, anyways, this line of yours: std::sort(input.begin(), input.end()): is redundant as I mentioned in comments: // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); That is, it's already sorted
Vlad
It's just to show that I expect it to be sorted
Yiğit
cbook
Anonymous
cbook
add ! or # or /get in front