Posts

Showing posts from 2019

Structure of C++

Image
Structure of C++   Line 01 : //my first program in C++ Two slash signs indicate that the rest of the line is a comment inserted by the programmer but which has no effect on the behavior of the program. programmers use them to include short explanations or observations concerning the code or program. in this case, it is a brief introductory description of the program Line 02 : #include<iostream> Lines beginning   with a hash sign(#) are directives read interpreted by what is know as the preprocessor. They are special lines interpreted before the compilation of the program itself begins. In this case the directive #include<iostream> instructs the preprocessor to include a section of standard C++ code know as header iostream that allows to perform standard input and output operations, such as writing the output of this program (HELLO WORLD) to the screen. Line 03 : using namespace std; All the elements of the stranded C++ library are declared with in what is ...

Sample Qustion 12

Image
Write a C++ program to multiply 2 arrays of size 3*4 and 4*2.RTead values for 2 arrays from user      #include <iostream>     using namespace std;     int main()     {         int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;         cout << "Enter rows and columns for first matrix: ";         cin >> r1 >> c1;         cout << "Enter rows and columns for second matrix: ";         cin >> r2 >> c2;         while (c1!=r2)         {             cout << "Error! column of first matrix not equal to row of second.";        ...

Sample Qustion 11

Image
Write a C++ program to add given 2 arrays.      int arr1[3][2]={{12,45},{21,89},{20,9}}      int arr2[3][2]={{20,15},{30,10},{4,7}}      #include <iostream>     using namespace std;     int main()     {         int a[3][2]={{14,15},{21,89},{20,9}};         int b[3][2]={{20,15},{30,10},{4,7}};         int sum [3][2];         int r =3;         int c = 2;         for(int i = 0; i < r; ++i)             for(int j = 0; j < c; ++j)                 {              ...

Sample Qustion 10

Image
Write a C++ program to display              a. Smallest value in each column              b. Smallest value in each row              c. Largest value in each column              d. Largest value in each row              e. Overall smallest value and largest value              f. Column name of the overall largest                             value                         ...

Sample Qustion 9

Image
Write a C++ program to display the smallest and greatest of given values. It also displays the value that occurs the most.              2,5,12,78,21,56,90,32,12,90,90,12  #include<iostream> using namespace std; int main() {     int arr[15] = {2,5,12,78,21,56,90,32,12,90,90,12};     int maxnum = arr[0];     int minnum = arr[0];   for (int i = 0; i < 12; i++)     {       if (arr[i] > maxnum)         {           maxnum = arr[i];         }       else if (arr[i] < minnum)         {           minnum = arr[i];         }     }   ...

Sample Qustion 8

Image
Write a C++ program to find the all the composite numbers below 100. #include<iostream> using namespace std; int main() {     int i,n,factor;     for(n=2;n<=100;n++)     {          for(i=1;i<n;i++)          {               if(n%i==0)               {                    factor=i;               }          }          if(factor>1)          {               cout << n ...

Sample Qustion 7

Image
Write a C++ program to convert given binary number into a decimal number. #include <iostream> using namespace std; int binaryToDecimal(int n) {     int num = n;     int dec_value = 0;     int base = 1;     int temp = num;     while (temp) {         int last_digit = temp % 10;         temp = temp / 10;         dec_value += last_digit * base;         base = base * 2;     }     return dec_value; } int main() {     int num;     cout << "enter number : " << endl;     cin >> num;     cout << binaryToDecimal(num) << endl;      } download file  cpp file do you have any qustion please comment clic...

Sample Qustion 6

Image
Write a C++ program to convert given decimal number into binary number.   #include <iostream>   using namespace std;   int main()   {   int a[10], n, i;   cout<<"Enter the number to convert: ";   cin>>n;   for(i=0; n>0; i++)   {   a[i]=n%2;   n= n/2;   }   cout<<"Binary of the given number= ";   for(i=i-1 ;i>=0 ;i--)   {   cout<<a[i];   }      } download file  cpp file do you have any qustion please comment click the advertisement to help for me ....

Sample Qustion 5

Image
Write a C++ program to read the year and the month number from user. Output number of days in that month. Consider the concept leap year. #include<iostream> using namespace std; int main() {    int year , month;    cout << "Enter year : " ;    cin >> year;    cout << "Enter Month : " ;    cin >> month;    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))       cout<<year<<" is a leap year" << endl;    else       cout<<year<<" is not a leap year" << endl;     if( month == 2)     {         if((year%400==0) || (year%4==0 && year%100!=0))             cout << "29 days in this month" << endl;         else  ...

Sample Qustion 4

Image
Write a C++ program to find whether given string is a palindrome or not. #include<iostream> using namespace std; int main() {     int i,j,len,flag=1;     char a[20];     cout<<"Enter a string:";     cin>>a;     for(len=0;a[len]!='\0';++len);     for(i=0,j=len-1;i<len/2;++i,--j)     {         if(a[j]!=a[i])             flag=0;     }     if(flag==1)         cout<<"\nThe string is Palindrome";     else         cout<<"\nThe string is not Palindrome";             cout << endl;            return 0; } download file  cpp file   do you h...

Sample Qustion 3

Image
Write a C++ program to find the reverse of a given number and check whether it is a palindrome or not. #include<iostream> using namespace std; int main() {     int n, num, digit, rev = 0;     cout << "Enter number" << endl;     cin >> num;     n = num;     do     {             digit = num %10;             rev = (rev * 10) + digit;             num = num / 10;     }     while( num !=0);     cout << rev << endl;     if(n == rev)     {         cout <<"is palindrome" << endl;     }     else     {    ...

Sample Qustion 2

Image
Write a C++ program to read a string input from the user and removes all characters except alphabets (remove all numbers, special characters)     #include<iostream>     #include<string>     using namespace std;     int main()     {         string line;         cout << "Enter a string: " << endl;         getline(cin, line);         for(int i = 0; i < line.size(); ++i)         {             if (!((line[i] >= 'a' && line[i]<='z') || (line[i] >= 'A' && line[i]<='Z')))             {               ...

Sample Qustion 1

Image
Write a C++ program to calculate the sum of the digits of a number until the number is a single digit. #include <iostream> using namespace std; int main() {     int number ;     cout << "enter number :" << endl;     cin >> number;     int res;     if(number)         res = number % 9 == 0 ? 9 : number % 9 ;     else         res = 0;     cout<<res;       return 0; } download file  cpp file do you have any qustion please comment  click the advertisement to help for me ....