Skip to main content

Posts

Showing posts from February, 2020

A simple calculator for adding and subtracting in c++

A simple calculator for adding and subtracting in c++











In this post, I write a code about very simple calculator in c++. Actually it is the problem in e-olymp.com
If you're not familiar with this website then you can go below link:
https://www.e-olymp.com/en/problems/7411


Input is in this form : 

                                             x+5=2  or 1+x=4  or  1+4=x
In the output we give the value of x.

It has very simple solution. That's why i give there only code and when you read this code line-by-line you easily understand it     :)

Solution:


#include<iostream>#include<string>using namespace std;int main(){ string statement;cin>>statement; int last_number = 0; if(statement[statement.length()-1] == '0' || statement[statement.length()-1] == '1'|| statement[statement.length()-1] == '2' || statement[statement.length()-1] == '3'|| statement[statement.length()-1] == '4' || statement[statement.length()-1] == '…

Matrix multiplication

Matrix multiplication



#include<iostream>using namespace std;int main(){// First matrixint row1, column1,i,j;cout<<"Enter the size of first matrix"<<endl;cout<<"Enter column: ";cin>>column1;cout<<"Enter row: ";cin>>row1; int matrix1[column1][row1]; for(i=0;i<column1;i++){ for(j=0;j<row1;j++){ cout<<"Enter "<<"matrix1["<<i<<"]["<<j<<"] = ";cin>>matrix1[i][j];} } // Second matrixint row2, column2;cout<<"Enter the size of second matrix"<<endl;cout<<"Enter column: ";cin>>column2;cout<<"Enter row: ";cin>>row2; int matrix2[column2][row2]; for(i=0;i<column2;i++){ for(j=0;j<row2;j++){ cout<<"Enter "<<"matrix2["<<i<<"]["&…