C++ Program to perform Decimal to Binary Conversion [DEVCPP/GCC]

PROGRAM

// Program to perform Decimal to Binary Conversion

#include <iostream>

using namespace std;

int main()
{
        long dec,num;
        int bin[30],i=0,j,rem;

        cout<<"ENTER DECIMAL VALUE: ";
        cin>>dec;

        while(dec>0)
        {
                rem=dec%2;
                bin[i]=rem;
                dec=dec/2;
                i++;
        }

        cout<<"\nBINARY EQUIVALENT: ";

        for(j= (i-1) ; j>=0 ; j--)
        {
                cout<<bin[j];
        }

         return 0;
}

OUTPUT

C++ Program to perform Decimal to Binary Conversion with output

C++ Program to print Floyd Triangle [DEVCPP/GCC]

PROGRAM

//Program to print a pattern (Floyd Triangle)

# include<iostream>

using namespace std;

int main()
 {
      int i,j,n,num=1;

      cout<<"ENTER THE NUMBER OF ROWS: \n";
      cin>>n;
      cout<<endl;

      for(i=0 ; i<n ; i++)
      {
              for(j=0 ; j<=i ; j++, num++)
             {
                     cout<<num<<" ";
             }
             cout<<endl;
     }
   
     return 0;
 }


OUTPUT

C++ Program to print Floyd Triangle with output

C++ Program to perform Binary to Decimal Conversion [DEVCPP/GCC]

PROGRAM

// Program to perform Binary to Decimal Conversion

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
        int i=0,digit;
        long bin;
        long dec=0;

        cout<<"ENTER BINARY NUMBER: ";
        cin>>bin;

        while(bin>0)
        {
                digit=bin%10;                  
                dec=dec+(pow(2,i)*digit);
                bin=bin/10;
                i++;
        }

        cout<<"DECIMAL EQUIVALENT: "<<dec;
        return 0;
}

OUTPUT

C++ Program to perform Binary to Decimal Conversion with output

C++ Program to find the second highest element in a given array [DEVCPP/GCC]

INT_MIN

As the name suggests, it refers to the minimum value of integer datatype.

PROGRAM

//Program to find the second highest element in a given array

#include <iostream>

using namespace std;

int main()
{
        int num [10],i,max,SecondMax;
        max=SecondMax=INT_MIN;

// Calculating the highest element of the array
        for(i=0 ; i<10 ; i++)
        {
                cout<<"ENTER "<< i<<" ELEMENT: ";
                cin>>num [i];

                if(num [i]>max)
                {
                        max=num [i];
                }
        }
 
        // Calculating the second highest element
        for(i=0;i<10;i++)
        {
                if(num [i]==max)
                {
                        continue;
                }
                else if(num [i]>SecondMax)
                {
                        SecondMax=num [i];
                 }
        }

        cout<<"\nMAXIMUM ELEMENT IS "<<max;
        cout<<"\nSECOND MAXIMUM ELEMENT IS "<<SecondMax;

        return 0;
}

OUTPUT

C++ Program to find the second highest element in a given array with output


C++ Program to count the number of vowels in a string [DEVCPP/GCC]


STEPS 

1. Initialize the count with 0.

2. Input the string, in this case a[10].

3. Initialize i with 0, check the value at a[i] against the cases mentioned in switch loop.

4. If the value tends to be equal to any of the case labels , increment the count.

5. Increment i by 1 and repeat steps 3 and 4 till a[i] is not equal to '\0' (null).

6. Display count.


PROGRAM

//Program to count the number of vowels in a string

# include<iostream>

using namespace std;

int main()
{
char a[10];
int i,j,count=0;

cin.getline(a,20); //Input the string

for(i=0;a[i]!='\0';i++)    // Loop to count the number of vowels
{
switch(a[i])
{
 
                case  'a' :  case 'A':
                case  'i'  :  case 'I':
                case  'e' :  case 'E':
                case  'o' :  case 'O':
                case  'u' :  case 'U':
             
                 count++ ;
}
}

cout<<count;   // Displaying count
return 0; 
}

OUTPUT

C++ Program to count the number of vowels in a string with output

FIND US ON FACEBOOK!