Most Commonly Asked Programs In C++ Language

Most Commonly Asked Programs In C++ Language


C Program To Perform Character Design : #02

Posted: 03 Jun 2013 04:45 AM PDT

C Program To Perform Character Design : #02

#include<stdio.h>
#include<conio.h>
int main()
{
 int num=0 ,col=0;
clrscr();

 printf(" \n Enter Number Of Rows : ");
 scanf("%d",&num);

 for(; num>=1; num--)
 {
        for(col=1; col<=num; col++)
        {     
              printf("@");
        }
        printf("\n");
 }
 getch();
 return 0;
}

Output :

@@@@@
@@@@   
@@@
@@
@

C Program To Perform Character Design : #01

Posted: 03 Jun 2013 04:23 AM PDT

This Post Contains A C Program To Perform Character Design : #01 With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Nested For-Loops' From C Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.
 
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.

  
C Program To Perform Character Design : #01

/* Declaration Of Header Files */

#include<stdio.h>
#include<conio.h>


/* Start Of Main Program */
int main()
{

 /* Declaration Of Variables */
 int num=0, row=0, col=0;

 /* Asking For The Input From User */
 printf(" \n Enter The Number Of Rows : ");
 scanf("%d",&num);


 /* Source Code For Character Design */
 for(row=1; num>=row; row++)
 {
      for(col=1; col<=num; col++)
            printf("@");
      printf("\n");
 }
 getch();
 return 0;
}

Output :
 
 Columns                 0  1  2  3  4

                    0         @@@@@
                    1         @@@@@
Rows           2         @@@@@
                    3         @@@@@
                    4         @@@@@

C++ Program To Perform Binary Search.

Posted: 03 Jun 2013 03:46 AM PDT

This Post Contains A C++ Program To Perform Binary Search. With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Binary Search' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Perform Binary Search.

/* Declaration Of Header Files */
#include<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{

/* Declaration Of Variables */
int i, j, x, dim, temp;
int low=0, high=0, mid=0;
int a[20];
clrscr();

/* Asking For The Input From User */
cout<<" \n Enter Dimension : ";
cin>>dim;
cout<<" \n Enter Values For Array : ";
for(i=0;i<dim;i++)
{
cin>>a[i];
}

// For Searching Values, They Should Be Sorted First.
// Sorting Values In Ascending Order.

for(i=0;i<dim;i++)
{
  for(j=i+1;j<dim;j++)
  {
    if(a[i]>a[j])
    {
       temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
  }
}

// Printing Values Of Array 'a' After Sorting.
cout<<" \n Sorted Array Is : ";
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}

/* Source Code For Computing Binary Search */
cout<<" \n Enter Value To Be Searched : ";
cin>>x;
low=0;
high=dim;
while(low<=high)
{
  mid=(low+high)/2;
  if(x<a[mid])
  {
     high=mid-1;
  }
  else
  {
     if(x>a[mid])
     {
        low=mid+1;
     }
     else
     {
        if(x==a[mid])
        {
           cout<<x<<" Is Located At Location "<<mid+1;
           break;
        }
     }
  }
}
getch();
}

Output :

Enter Dimension : 5

Enter 5 Values :
44  22  11  55  33

Sorted Array Is :
11  22  33  44  55

Enter Value To Be Searched : 33
33 Is Located At Location 3

C++ Program To Perform Linear Search.

Posted: 03 Jun 2013 03:39 AM PDT

This Post Contains A C++ Program To Perform Linear Search. With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Linear Search' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Perform Linear Search.
 
/* Declaration Of Header Files */
#include<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{

/* Declaration Of Variables */
int i, j, x, dim, t;
int a[20];
clrscr();

// Accepting Range Of Array From User.
cout<<" \n Enter Dimension For Array : ";
cin>>dim;

// Accepting Value For Array From User.
cout<<" \n Enter The Values For Array A : ";
for(i=0;i<dim;i++)
{
cin>>a[i];
}

// For Searching Values, They Should Be Sorted First.
// Sorting Values In Ascending Order.

for(i=0;i<dim;i++)
{
  for(j=i+1;j<dim;j++)
  {
    if(a[i]>a[j])
    {
       temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
  }
}

// Printing Values Of Array 'a' After Sorting.
cout<<" \n Sorted Array Is : ";
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}

/* Source Code For Computing Linear Search */
cout<<" \n Enter Value To Be Searched : ";
cin>>x;
for(i=0;i<dim;i++)
{
  if(x==a[i])
  {
     cout<<"\n"<<x<<" Is Located At Location "<<i+1;
  }
}
getch();
}

Output :

Enter Dimension :5

Enter 5 Values For Array 'a' :
4  2  5  1  3

Sorted Array 'a' Is :
1  2  3  4  5

Enter Value To Be Searched : 2
2 Is Located At Location 2.

C++ Program To Perform Bubble Sort In Descending Order.

Posted: 03 Jun 2013 03:32 AM PDT

This Post Contains A C++ Program To Perform Bubble Sort In Descending Order. With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Bubble Sort' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language
In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Perform Bubble Sort In Descending Order.


/* Declaration Of Header Files */
#include<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{
int i, j, dim=0, temp=0;
int a[20];
clrscr();

// Accepting Range Of Array From User.
cout<<" \n Enter Dimension : ";
cin>>dim;

// Accepting Values Of Array From User.
cout<<" \n Enter Values For Array : ";
for(i=0;i<dim;i++)
{
cin>>a[i];
}

// Printing Values Of Array.
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}

// Sorting Values In Descending Order.
for(i=1;i<=dim;i++)
{
  for(j=1; j<=(dim-i); j++)
  {
    if(a[j]<a[j+1])
    {
       temp=a[j];
       a[j]=a[j+1];
       a[j+1]=temp;
    }
  }
}

// Printing Values Of Array 'a' After Sorting.
cout<<" \n Sorted Array Is : ";
for(i=1;i<=dim;i++)
{
cout<<a[i]<<"\t";
}
getch();
}

Output :

Enter Dimension : 5

Enter 5 Values :
44  22  11  55  33

Sorted Array Is :
55  44  33  22  11

C++ Program To Perform Selection Sort In Ascending Order.

Posted: 03 Jun 2013 03:20 AM PDT

This Post Contains A C++ Program To Perform Selection Sort In Ascending Order With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Selection Sort' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.



C++ Program To Perform Selection Sort In Ascending Order.
 
/* Declaration Of Header Files */
#include<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{

/* Declaration Of Variables */
int i, j, dim=0, temp=0;
int a[20];

clrscr();

// Accepting Range Of Array From User.
cout<<" \n Enter Dimension : ";
cin>>dim;

// Accepting Values Of Array From User.
cout<<" \n Enter Values For Array : ";
for(i=0;i<dim;i++)
{
cin>>a[i];
}

// Printing Values Of Array.
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}

// Sorting Values In Ascending Order.
for(i=0;i<dim;i++)
{
  for(j=i+1;j<dim;j++)
  {
    if(a[i]>a[j])
    {
       temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
  }
}

// Printing Values Of Array 'a' After Sorting.
cout<<" \n Sorted Array Is : ";
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}
getch();
}

Output :

Enter Dimension : 5

Enter 5 Values :
44  22  11  55  33

Sorted Array Is :
11  22  33  44  55


Post a Comment