Most Commonly Asked Programs In C++ Language

Most Commonly Asked Programs In C++ Language


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

Posted: 10 Jun 2013 01:02 AM PDT

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 Turbo C/C++3.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<stdio.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 */
    printf(" \n Enter The Dimension Of Array : ");
    scanf("%d", &dim);
    printf(" \n Now Enter The %d Elements Into Array : ", dim);
    for( e=0; e<dim; e++ )
    {
        scanf("%d", &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 */
    printf(" \n Highest Element Is : ", highest);
    printf(" \n 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

C Program For Swapping Of Two Arrays.

Posted: 10 Jun 2013 12:50 AM PDT

This Post Contains A C Program For Swapping Of Two Arrays With Correct Source Code & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.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.


When It Comes To Arrays, Most Of Us Get Confused & Hence Some Of Us Find Or Thinks That This Particular Concept Is Complicated As Well As Tricky. But The Following Code Will Make It Really Simple For You To Understand.

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

  
C Program For Swapping Of Two Arrays.

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

/* Start Of Main Program */
void main()
{
   /* Declaration Of Variables */
   int a[10], b[10], f, p;
   clrscr();
 
   /* Asking For The Input From User */
   printf(" \n Enter Dimension : ");
   scanf("%d", &f);
   printf(" \n Enter %d Values For Array A : ", f);
   for ( p = 0; p < f; p++ )
   {
        scanf("%d", &a[p]);
   }

   /* Asking For The Input From User */
   printf(" \n Enter %d Values For Array B : ", f);
   for ( p = 0; p < f; p++ )
   {
     scanf("%d", &b[p]);
   }
 
   /* Printing The Values Of Array A */
   printf(" \n Values For Array A : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", a[p]);
   }

   /* Printing The Values Of Array B */
   printf(" \n Values For Array B : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", b[p]);
   }
 
   /* Source Code For Swapping Of Two Arrays */
   for ( p = 0; p < f; p++ )
   {
     a[p] = a[p] + b[p];
     b[p] = a[p] - b[p];
     a[p] = a[p] - b[p];
   }

   /* Printing The Output On The Screen/Console */
   printf(" \n After Swapping : \n ");
   printf(" Values For Array A : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", a[p]);
   }
   printf(" Values For Array B : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", b[p]);
   }
  
   getch();
}
/* End Of Main Program */

Output  :

Enter Dimension  :  3

Enter 3 Values For Array A  :  1  2  3

Enter Dimension  :  3

Enter 3 Values For Array B  :  4  5  6

Values Of Array A  :  1  2  3

Values Of Array B  :  4  5  6

After Swapping  :

Values Of Array A  :   4  5  6

Values Of Array B  :   1  2  3



  


Post a Comment