Templates in C++

What are Templates: Templates in C++  are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. C++ uses Standard Template Library (STL) for templates. A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and … Read more

Time Complexity: How to calculate?

If you are learning DSA and algorithms, it is really important for you to know how to calculate the Time complexity for any given algorithm. Lets understand the same with example Time Complexity Calculation: The most common metric for calculating time complexity is Big O notation. This removes all constant factors so that the running … Read more

Matrix multiplication in C++

How matrix multiplication in C++ Works:   Input two matrices. Run 3 for loops (i,j,k). Multiplication will be addition of First_Matrix[i][k]*Second_Matrix[k][j] for each element. Resultant matrix is stored in third Matrix.   CODE: #include<iostream> using namespace std; int main(){ //Using const int for array size const int row=2,col=2; // if not use const error found … Read more

Table of a number in C++

We all know what is table of a number. Here is the code to print table of a number in c, entered by the user.   CODE: #include<iostream> using namespace std; int main() { int num; cout<<"Enter Number To Find Multiplication table "; cin>>num; for(int a=1;a<=10;a++) { cout<<num<<" * "<<a<<" = "<<num*a<<endl; } return 0; … Read more