Posts

Cpp program to find Quotient and Remainder

 Following is the code which help in the understanding how to compute quotient and remainder. Code: #include <iostream> using namespace std; int main() {         int divis, divid, quot, rem;     cout << "Enter dividend :-"<<endl;     cin >> divid;     cout << "Enter divisor:- "<<endl;     cin >> divis;     quot = divid / divis;     rem = divid % divis;     cout << "Quotient = " << quot << endl;     cout << "Remainder = " << rem<<endl;     return 0; } Output: In the above program, declare 4 variables of int data type and take input from the user by input method then divide the dividend by divisor store in quotient which is the quotient .  The modulus of dividend and divisor is store in the remainder because modulus computes the remainder of the two number. If you have any problem in understanding of the above program then write a query in the below comment section.

CPP Program multiply the two matrices

 In this program, discussion about the multiple the two matrices in the cpp programming language. But you have enough knowledge to understand the whole program. If you do not have knowledge then visit c++ 2D arrays c++ loops c++ pointers Code: #include<iostream> using namespace std; int main() { int firstmat[10][10], secondmat[10][10], multi[10][10],i, j,firstrow,firstcol,secondrow,secondcol; cout << "Enter rows and column for first matrix: "; cin >> firstrow >> firstcol; cout << "Enter rows and column for second matrix: "; cin >> secondrow >> secondcol; cout<< "Enter elements of matrix 1:" << endl; for(i = 0; i < firstrow; ++i) { for(j = 0; j < firstcol; ++j) { cout << "Enter elements a"<< i + 1 << j + 1 << ": "; cin >> firstmat[i][j]; } } cout << endl << "Enter elements of matrix 2:" <<

CPP Program find the largest number in the array

  In this program, you will learn about the find the largest number in the array in the cpp programming language. If you have knowledge about the c++ array, the c++ loop help in understanding the program. Code: #include <iostream> using namespace std; int main() {     int i, n;     float arr[10]={1,2,3,4,5,6,7,8,9,10};     // Loop to store largest number to arr[0]     for(i = 1;i < n; ++i)     {        // Change < to > if you want to find the smallest element        if(arr[0] < arr[i])            arr[0] = arr[i];     }     cout << "Largest element  = " << arr[0]<<endl;     return 0; } Output: Largest element  = 10

CPP Program find the frequency of characters in a string

  Here, you will learn about how to find the frequency of the character in the string in the cpp programming language. Code: #include <iostream> using namespace std; int main() {     string str = "CPP is best for gaming";     char checkChar = 'i';     int count = 0;     for (int i = 0; i < str.size(); i++)     {         if (str[i] ==  checkChar)         {             ++ count;         }     }     cout << "Number of  " << checkChar << " : " << count;     return 0; }  In the above program, find the length of the string then apply the for loop with check if (str[i] ==  checkChar) increment in the count in each iteration. The loop is iterate until condition the end of the string. If you have any problem in the above program write your query in the below comment section

CPP program Accessing the element of array by using pointer

  Here, in this example of the cpp program declare an array of five lengths with integer type and take input from the user then access all the elements of the array through a pointer. For understanding you have knowledge about the following topics: C++ pointers C++ Arrays Code: #include <iostream> using namespace std; int main() {    int arr[5];    cout << "Enter elements :- ";    for(int i = 0; i < 5; ++i)    {       cin >> arr[i];   }    cout << "You entered arr :- "<<endl;;    for(int i = 0; i < 5; ++i)    {       cout <<  *(arr + i)<<endl;   }    return 0; } Output: Enter elements:- 1 2 3 4 5 You entered arr:- 1 2 3 4 5

CPP Program to find length of string

Here,you will find the knowledge about how to find the length of the string or size of string in the cpp programming language. To find the length of string object size () and length() both functions are used.They are synonyms to each other and exactly done same job. Code: #include <iostream> using namespace std; int main() {     string str = "C++ Programming";     // can  use str.length()     cout << "String Length = " << str.length()<<endl;     //also use str.size()      cout << "String Length = " << str.size();     return 0; } Output: String Length = 15 String Length = 15 In the cpp, another way to calculate the length by using a function  from the library cstring Code: #include <iostream> #include<cstring> using namespace std; int main() {     char str[] = "C++ Programming";     cout << "String Length = " << strlen(str)<<endl;          return 0; } Output: String Length

CPP Program convert octal to binary

 In this example, you will learn about the conversion of octal to binary number in the cpp programming language .you must have knowledge about the following topics to understand the working of the program. Cpp while loop Cpp input method Cpp output method Following is the code of conversion. Code: #include <iostream> #include <cmath> using namespace std; int main() {     int octalNumber,original;     cout << "Enter an octal number: ";     cin >> octalNumber; original=octalNumber;     int decimalNumber = 0, i = 0;     long long binaryNumber = 0;     while(octalNumber != 0)     {         decimalNumber += (octalNumber%10) * pow(8,i);         ++i;         octalNumber/=10;     }     i = 1;     while (decimalNumber != 0)     {         binaryNumber += (decimalNumber % 2) * i;         decimalNumber /= 2;         i *= 10;     }      cout << original << " in octal = " << binaryNumber << " in binary";       return 0; }