28 January, 2013

C++ Program To Find A Leap Year.

This Post Contains A C++ Program To Find A Leap Year With Correct Source Code & Output.
This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'If...else' 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 Find A Leap Year.

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

/* Start Of Main Program */
void  main()
{
         /* Declaration Of Variables */
         int Num=0;
         clrscr();
      
         /* Asking For The Input From User */  
         cout << " \n Please Enter The Year = \t " ;
         cin >> Num ;
      
         /* Code For Determining The Leap Year */
         if ( ( Num % 4 == 0 ) && (Num % 100 != 0) || (Num % 400 == 0 ) )
                cout << " \n The Entered Year Is A 'LEAP YEAR' " ;
         else
                cout << " \n The Entered Year Is Not A 'LEAP YEAR' " ;

         getch();
}
/* End Of Main Program */



C Program To Find A Leap Year.

This Post Contains A C Program To Find A Leap Year With Correct Source Code & Output.
 This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'If...else' 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 Find A Leap Year.

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

/* Start Of Main Program */
void  main()
{
         /* Declaration Of Variables */
         int Num=0;
         clrscr();
     
          /* Asking For The Input From User */ 
         printf( " \n Please Enter The Year = \t " );
         scanf( " %d " , &Num );


         if ( ( Num % 4 == 0 ) && (Num % 100 != 0) || (Num % 400 == 0 ) )
                printf ( " \n The Entered Year Is A 'LEAP YEAR' " );
         else
                printf ( " \n The Entered Year Is Not A 'LEAP YEAR' " );
     
         getch();
}
/* End Of Main Program */ 




21 January, 2013

C Program For Variable Exchange - 02.

This Post Contains A C Program For Exchanging The Values Of Two Variables Without Using A Third [Temporary] Variable With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of Variable Manipulation 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 For Variable Exchange.

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

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

    /* Declaration Of Variables */
    int a = 0, b = 0;

    clrscr();

    /* Accepting The Values Of Two Variabe From User */
    printf("\n Please Enter Number For Variable A : ");
    scanf("%d", &a);
    printf("\n Please Enter Number For Variable B : ");
    scanf("%d", &b);

    printf("\n Values Of Two Variables [i.e. A & B] Before Exchange : %d  %d", a, b);

    /* Main Code For Exchanging The Values Of Two Variables Using Temporary Variable */
    b =  a + b;
    a =  b - a;
    b =  b - a;

    /* Printing The Values Of Two Variables After Exchange */
    printf("\n\n Values Of Two Variables [i.e. A & B] After  Exchange : %d  %d", a, b);

    getch();
}

/* End Of Program */

Output :


Please Enter Number For Variable A  :  1
Please Enter Number For Variable B  :  2
Values Of Two Variables [i.e. A & B] Before Exchange  :  1  2
Values Of Two Variables [i.e. A & B] After Exchange  :  2  1




C Program For Variable Exchange - 01.

This Post Contains A C Program For Exchanging The Values Of Two Variables Using A Third [Temporary] Variable With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of Variable Manipulation 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 For Variable Exchange.

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

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

    /* Declaration Of Variables */
    int a = 0, b = 0, Temp = 0;

    clrscr();

    /* Accepting The Values Of Two Variabe From User */
    printf("\n Please Enter Number For Variable A : ");
    scanf("%d", &a);
    printf("\n Please Enter Number For Variable B : ");
    scanf("%d", &b);

    printf("\n Values Of Two Variables [i.e. A & B] Before Exchange : %d  %d", a, b);

    /* Main Code For Exchanging The Values Of Two Variables Using Temporary Variable */
    Temp = a;
    a = b;
    b = Temp;

    /* Printing The Values Of Two Variables After Exchange */
    printf("\n\n Values Of Two Variables [i.e. A & B] After  Exchange : %d  %d", a, b);

    getch();
}

/* End Of Program */

Output :


Please Enter Number For Variable A  :  1
Please Enter Number For Variable B  :  2
Values Of Two Variables [i.e. A & B] Before Exchange  :  1  2
Values Of Two Variables [i.e. A & B] After Exchange  :  2  1




C Program For Addition Of 'N' Numbers.

This Post Contains A C Program For Addition Of 'N' Numbers With Correct Source Code & Output.
This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of ''For-loop' 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 For Addition Of 'N' Numbers.

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

void main()
{
    int i=0,Num=0,Sum=0;
    clrscr();
    printf("\n Please Enter The Number : \t");
    scanf("%d",&Num);
    for( i=0 ;i  <= Num ; i++ )
    {
        Sum = Sum + i;
    }
    printf(" \n The Addition Of Nos Till %d Is : \t %d ", Num, Sum );

    getch();
}

Output :

Please Enter The Number  :  10

The Addition Of Nos Till 10 Is  :  55




09 January, 2013

C++ Program For Multiplication Of Two Matrices.

This Post Contains A C++ Program For Multiplication Of Two Matrices With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'for-Loops' & 'Arrays' 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 For Multiplication Of Two Matrices.

/* Declaring The Header Files */
#include <iostream.h>
#include <conio.h>

/* Start Of Main Program */
void main()
{
    /* Declaration Of Variables */
    int a[10][10],b[10][10],d[10][10];
    int i, j, k, r, c, p, q;
   
    clrscr();
   
    /* Accepting Dimensions Of Matrix 'A' From User */
    cout << " Enter Order Of Matrix A : ";
    cin >> r >> c;
   
    /* Accepting Values For Matrix 'A' From User */
    cout << " Enter " << r*c << " Values : ";
    for(i=0; i<r; i++)
    {   
           for(j=0; j<c; j++)
       {
              cin >> a[i][j];
       }  
    }

    /* Accepting Dimensions Of Matrix 'B' From User */
    cout << " Enter Order Of Matrix B : ";
    cin>>p>>q;
   
    /* Accepting Values For Matrix 'B' From User */
    cout << " Enter " << p*q << " Values : ";
    for(i=0; i<p; i++)
    {   
           for(j=0; j<q; j++)
       {
              cin >> b[i][j];
       }  
    }

    /* Printing Values Of Matrix 'A' */
    cout << " \n Elements Of Array A : ";
    for(i=0; i<r; i++)
    {
       cout << " \n";
       for(j=0' j<c; j++)
       {
          cout << a[i][j] << "\t";
       }
    }

    /* Printing Values Of Matrix 'B' */
    cout << "\n Elements Of Array B : ";
    for(i=0; i<p; i++)
    {
       cout << "\n";
       for(j=0; j<q; j++)
       {
          cout<<b[p][q]<<"\t";
       }
    }

    /* Multiplication Of Two Matrices Will Take Place If & Only If 'rows' & 'columns' Of Two Matrices Are Equal */
    /* Checking If 'rows' & 'columns' Of Two Matrices Are 'Equal' */
    if( r==p && c==q )
    {
        for(i=0; i<r; i++)
        {
           for(j=0; j<q; j++)
           {
                  d[i][j] = 0;
                  for(k=0; k<p; k++)
                     d[i][j] = a[i][k] * b[k][j] + d[i][j];;
               }
            }

        /* Printing Values Of Resultant Matrix i.e 'D' */
        cout << " \n Elements Of Resultant Array 'D' : ";
        for(i=0; i<p; i++)
        {
           cout<<"\n";
           for(j=0' j<q; j++)
           {
              cout << d[p][q] << "\t";
           }
        }
    }
    else
    {
        cout << " \n Multiplication Of Two Matrices Is Not Possible ";
    }
    getch();
}
/* End Of Main Program */

# Note : Please Click Here To View Other Programs Related To Matrices.

Output :

Enter Order Of Matrix 'A' : 3  3
Enter 9 Values :  1  2  3  4  5  6  7  8  9

Elements Of Array 'A' :
1  2  3
4  5  6
7  8  9

Enter Order Of Matrix 'B' : 3  3
Enter 9 Values :  1  2  3  4  5  6  7  8  9

Elements Of Array 'B' :
1  2  3
4  5  6
7  8  9

Elements Of Resultant Array 'D' :
30   36   42
66   81   96
102  126  150




04 January, 2013

C Program To Print Hello On Screen/Console.

This Post Contains A C Program To Print Hello On Screen/Console With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Printing Characters' 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 Print Hello On Screen/Console.
/* Declaring Header Files */

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

/* Start Of Main Program */
main()

{

        /* Clearing The Screen */
        clrscr();

        printf ( " \n " );

        printf ( " \t " );

        /* Printing The Characters Onto Screen/Console */

        printf ( " HELLO WORLD " );

        getch();

        return (0);

}
/* End Of Main Program */

Output:
HELLO WORLD.

Just Remember  The Following Points In Order To Become A Good Programmer :

  • Every Program Require & Has One & Only One 'main()' Function.
  • Use Of More Than One 'main()' Is Illegal.
  • Use Uniform Notation Throughout Your Code i.e. Hungarian Notation.
  • Every Program [ Executable ] Statement Should End With A Semi-Colon.
  • All Variables Must Be Declared With Thier Data Types Before They Are Used.
  • Make Sure You Include Standard Header Files @ Start Of Program.
  • When Braces Are Used To Group The Statements, Make Sure That The Opening Brace Has A Corresponding Closing Brace.
  • A Comment Can Be Inserted Almost Anywhere A Space Can Appear. Use Of Appr. Comments In Proper Places Increases Readability & Understandability Of The Program & Helps User In Debugging & Testing.









C++ Program For Subtraction Of Two Matrices.

This Post Contains A C++ Program For Subtraction Of Two Matrices With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-loop' & 'Nested 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 For Subtraction Of Two Matrices.

/* Declaring The Header Files */
#include <iostream.h>
#include <conio.h>

/* Start Of Main Program */
void main()
{
    /* Declaration Of Variables */
    int a[10][10],b[10][10],d[10][10];
    int i, j, r, c, p, q;
   
    clrscr();
   
    /* Accepting Dimensions Of Matrix 'A' From User */
    cout << " Enter Order Of Matrix A : ";
    cin >> r >> c;
   
    /* Accepting Values For Matrix 'A' From User */
    cout << " Enter " << r*c << " Values : ";
    for(i=0; i<r; i++)
    {   
           for(j=0; j<c; j++)
       {
              cin >> a[i][j];
       }  
    }

    /* Accepting Dimensions Of Matrix 'B' From User */
    cout << " Enter Order Of Matrix B : ";
    cin>>p>>q;
   
    /* Accepting Values For Matrix 'B' From User */
    cout << " Enter " << p*q << " Values : ";
    for(i=0; i<p; i++)
    {   
           for(j=0; j<q; j++)
       {
              cin >> b[i][j];
       }  
    }

    /* Printing Values Of Matrix 'A' */
    cout << " \n Elements Of Array A : ";
    for(i=0; i<r; i++)
    {
       cout << " \n";
       for(j=0' j<c; j++)
       {
          cout << a[i][j] << "\t";
       }
    }

    /* Printing Values Of Matrix 'B' */
    cout << "\n Elements Of Array B : ";
    for(i=0; i<p; i++)
    {
       cout << "\n";
       for(j=0; j<q; j++)
       {
          cout<<b[p][q]<<"\t";
       }
    }

    /* Subtraction Of Two Matrices Will Take Place If & Only If 'rows' & 'columns' Of Two Matrices Are Equal */
    /* Checking If 'rows' & 'columns' Of Two Matrices Are 'Equal' */
    if( r==p && c==q )
    {
        for(i=0; i<r; i++)
        {
           for(j=0; j<q; j++)
           {
                  d[i][j] = a[i][j] - b[i][j];
               }
            }

        /* Printing Values Of Resultant Matrix i.e 'D' */
        cout << " \n Elements Of Resultant Array 'D' : ";
        for(i=0; i<p; i++)
        {
           cout<<"\n";
           for(j=0' j<q; j++)
           {
              cout << d[p][q] << "\t";
           }
        }
    }
    else
    {
        cout << " \n Subtraction Of Two Matrices Is Not Possible ";
    }
    getch();
}
/* End Of Main Program */

 # Note : Please Click Here To View Other Programs Related To Matrices.

Output :

Enter Order Of Matrix 'A' : 3  3
Enter 9 Values :  2  4  6  8  10  12  14  16  18

Elements Of Array 'A' :
2   4   6
8   10  12
14  16  18

Enter Order Of Matrix 'B' : 3  3
Enter 9 Values :  1  2  3  4  5  6  7  8  9

Elements Of Array 'B' :
1  2  3
4  5  6
7  8  9

Elements Of Resultant Array 'D' :
1  2  3
4  5  6
7  8  9




C++ Program For Addition Of Two Matrices.

This Post Contains A C++ Program For Addition Of Two Matrices With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-loop' & 'Nested 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 For Addition Of Two Matrices.

/* Declaring The Header Files */
#include <iostream.h>
#include <conio.h>

/* Start Of Main Program */
void main()
{
    /* Declaration Of Variables */
    int a[10][10],b[10][10],d[10][10];
    int i, j, r, c, p, q;
   
    clrscr();
   
    /* Accepting Dimensions Of Matrix 'A' From User */
    cout << " Enter Order Of Matrix A : ";
    cin >> r >> c;
   
    /* Accepting Values For Matrix 'A' From User */
    cout << " Enter " << r*c << " Values : ";
    for(i=0; i<r; i++)
    {   
           for(j=0; j<c; j++)
       {
              cin >> a[i][j];
       }  
    }

    /* Accepting Dimensions Of Matrix 'B' From User */
    cout << " Enter Order Of Matrix B : ";
    cin>>p>>q;
   
    /* Accepting Values For Matrix 'B' From User */
    cout << " Enter " << p*q << " Values : ";
    for(i=0; i<p; i++)
    {   
           for(j=0; j<q; j++)
       {
              cin >> b[i][j];
       }  
    }

    /* Printing Values Of Matrix 'A' */
    cout << " \n Elements Of Array A : ";
    for(i=0; i<r; i++)
    {
       cout << " \n";
       for(j=0' j<c; j++)
       {
          cout << a[i][j] << "\t";
       }
    }

    /* Printing Values Of Matrix 'B' */
    cout << "\n Elements Of Array B : ";
    for(i=0; i<p; i++)
    {
       cout << "\n";
       for(j=0; j<q; j++)
       {
          cout<<b[p][q]<<"\t";
       }
    }

    /* Addition Of Two Matrices Will Take Place If & Only If 'rows' & 'columns' Of Two Matrices Are Equal */
    /* Checking If 'rows' & 'columns' Of Two Matrices Are 'Equal' */
    if( r==p && c==q )
    {
        for(i=0; i<r; i++)
        {
           for(j=0; j<q; j++)
           {
                  d[i][j] = a[i][j] + b[i][j];
               }
            }

        /* Printing Values Of Resultant Matrix i.e 'D' */
        cout << " \n Elements Of Resultant Array 'D' : ";
        for(i=0; i<p; i++)
        {
           cout<<"\n";
           for(j=0' j<q; j++)
           {
              cout << d[p][q] << "\t";
           }
        }
    }
    else
    {
        cout << " \n Addition Of Two Matrices Is Not Possible ";
    }
    getch();
}
/* End Of Main Program */

# Note : Please Click Here To View Other Programs Related To Matrices.

Output :

Enter Order Of Matrix 'A' : 3  3
Enter 9 Values :  1  2  3  4  5  6  7  8  9

Elements Of Array 'A' :
1  2  3
4  5  6
7  8  9

Enter Order Of Matrix 'B' : 3  3
Enter 9 Values :  1  2  3  4  5  6  7  8  9

Elements Of Array 'B' :
1  2  3
4  5  6
7  8  9

Elements Of Resultant Array 'D' :
2   4   6
8   10  12
14  16  18





03 January, 2013

C++ Program To Find Highest And Lowest Elements Of An Array.

This Post Contains A C++ Program To Find Highest And Lowest Elements Of An Array With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays' & 'For-loop' 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 Find Highest And Lowest Elements Of An Array.
 
/* Declaration Of Header Files */
#inlcude<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{
    /* Declaration Of Variables */ 
    int a[20];
    int e, dim, highest, lowest;
    clrscr();

    /* Asking For The Input From User */
    cout << " Enter The Dimension Of Array : ";
    cin >> dim;
    cout << " Now Enter The " << dim << " Elements Into Array : ";
    for( e=0; e<dim; e++ )
    {
        cin >> a[e];
    }

    /* Source Code For Computing Highest And Lowest Elements Of An Array */
    highest=a[0];
    lowest=a[0];
    for( e=0; e<dim; e++ )
    {
        if( a[e] > highest )
        {
            highest = a[e];
        }
        if( a[e] < lowest )
        {
            lowest = a[e];
        }
    }

    /* Printing The Output Onto The Screen/Console */
    cout << " Highest Element Is : " << highest;
    cout << " Lowest Element Is : " << lowest;
    getch();
}
/* End Of Main Program */


Output :

Enter The Dimension Of Array : 5

Now Enter The 5 Elements Into Array : 1  2  3  4  5

Highest Element Is : 5

Lowest Element Is : 1




Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.