Example program passing array as function argument in C C++

Example program passing array as function argument in C C++

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

C में फाईल क्या होता है इसे क्यो बनाया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Introduction to File

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

Example program passing array as function argument in C

#include<stdio.h>
void display(int[],int);
int main()
{
    int a[5],i=0;
    printf("Enter values: ");
    for(i=0;i<5;i++)
    scanf("%d",&a[i]);
    display(a,5);
    return 0;
}
void display(int a[], int n)
{
    int i=0,sum=0;
    for(i=0;i<n;i++)
    {
        printf("Element = %d\n",a[i]);
        sum=sum+a[i];
    }
    printf("Sum = %d",sum);
}

Example program passing array as function argument in C++

#include<iostream>
using namespace std;
void display(int[],int);
int main()
{
    int a[5],i=0;
    cout<<"Enter values: ";
    for(i=0;i<5;i++)
    cin>>a[i];
    display(a,5);
    return 0;
}
void display(int a[], int n)
{
    int i=0,sum=0;
    for(i=0;i<n;i++)
    {
        cout<<"Element = "<<a[i]<<endl;
        sum=sum+a[i];
    }
    cout<<"Sum = "<<sum;
}

Output of Example program passing array as function argument in C C++

Example program for passing array as function argument in C

Other function based example programs in C C++

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Swapping using function call by reference
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Pointer to array example program in C C++

Pointer to array example program in C C++

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Pointer to array क्या होता है जानने के लिए देखें—Pointer to array in C

C Language में Pointer to Pointer क्या होता है जानने के लिए देखें— Pointer to pointer in C

Pointer to array example program in C

#include<stdio.h>
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        printf("Element = %d Address = %u\n",*ptr,ptr);
        ptr++;
    }
    return 0;
}

Pointer to array example program in C++

#include<iostream>
using namespace std;
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        cout<<"Element = "<<*ptr<<"Address = "<<ptr<<endl;
        ptr++;
    }
    return 0;
}

Output of Pointer to array example program in C C++

Pointer to array example program in C C++

More example programs of array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Merging two arrays
  8. Searching in array (Linear search)
  9. Sorting in array (Selection sort)
Share it to:

C C++ program for sorting in array-Selection sort

C C++ program for sorting in array-Selection sort

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Pointer to array क्या होता है जानने के लिए देखें—Pointer to array in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

C program for sorting in array-Selection sort

#include<stdio.h>
int main()
{
    int a[5],i,j,temp;
    printf("Enter values of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=4;i>0;i--)
    {
        for(j=0;j<i;j++)
        {
            if(a[j+1]<a[j])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    printf("Sorted Array: \n");
    for(i=0;i<5;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}

C++ program for sorting in array-Selection sort

#include<iostream>
using namespace std;
int main()
{
    int a[5],i,j,temp;
    cout<<"Enter values of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>a[i];
    }
    for(i=4;i>0;i--)
    {
        for(j=0;j<i;j++)
        {
            if(a[j+1]<a[j])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    cout<<"Sorted Array: \n";
    for(i=0;i<5;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

Output of C C++ program for sorting in array-Selection sort

C C++ program for sorting in array-Selection sort

More programs on array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Merging two arrays
  8. Searching in array (Linear search)
  9. Pointer to array
Share it to:

C C++ program for searching in array-Linear Sequential search

C C++ program for searching in array-Linear Sequential search

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

C program for searching in array-Linear Sequential search

#include<stdio.h>
int main()
{
    int a[5],i,key,flag=1;
    printf("Enter values of array: ");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter search key: ");
    scanf("%d",&key);
    for(i=0;i<5;i++)
    {
        if(a[i]==key)
        {
            printf("Search key is present in position %d",i+1);
            flag=0;
        }
    }
    if(flag==1)
    {
        printf("Search key is not present");
    }
    return 0;
}

C++ program for searching in array-Linear Sequential search

#include<iostream>
using namespace std;
int main()
{
    int a[5],i,key,flag=1;
    cout<<"Enter values of array: ";
    for(i=0;i<5;i++)
    {
        cin>>a[i];
    }
    cout<<"Enter search key: ";
    cin>>key;
    for(i=0;i<5;i++)
    {
        if(a[i]==key)
        {
            cout<<"Search key is present in position "<<i+1;
            flag=0;
        }
    }
    if(flag==1)
    {
        cout<<"Search key is not present";
    }
    return 0;
}

Output of C C++ program for searching in array-Linear Sequential search

C C++ program for searching in array-Linear Sequential search

Related array example programs in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Merging two arrays
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

C C++ program to merge two arrays

C C++ program to merge two arrays

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

C Language में character set क्या होता है जानने के लिए देखें—Character set of C

C Language में Character Set क्या होता है जानने के लिए देखें—Tokens in C

C program to merge two arrays

#include<stdio.h>
int main()
{
    int a1[5],a2[5],a3[10],i=0,j=0;
    printf("Enter elements of Array1:\n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a1[i]);
    }
    printf("Enter elements of Array1:\n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a2[i]);
    }
    for(i=0;i<10;i++)
    {
        if(i<5)
        {
         a3[i]=a1[i];
        }
        else
        {
            a3[i]=a2[j];
            j++;
        }
    }
    printf("Merged Array:\n");
    for(i=0;i<10;i++)
    {
        printf("%d ",a3[i]);
    }
    return 0;
}

C++ program to merge two arrays

#include<iostream>
using namespace std;
int main()
{
    int a1[5],a2[5],a3[10],i=0,j=0;
    cout<<"Enter elements of Array1:\n";
    for(i=0;i<5;i++)
    {
        cin>>a1[i];
    }
    cout<<"Enter elements of Array1:\n";
    for(i=0;i<5;i++)
    {
        cin>>a2[i];
    }
    for(i=0;i<10;i++)
    {
        if(i<5)
        {
         a3[i]=a1[i];
        }
        else
        {
            a3[i]=a2[j];
            j++;
        }
    }
    cout<<"Merged Array:\n";
    for(i=0;i<10;i++)
    {
        cout<<a3[i]<<" ";
    }
    return 0;
}

Output of C C++ program to merge two arrays

C C++ program to merge two arrays

Similar array programs in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

C C++ program to find smallest minimum element in array

C C++ program to find smallest minimum element in array

C Language की विशेषताओं एवं शक्तियों को जानने के लिए देखें—Features and Powers of C

C Language में character set क्या होता है जानने के लिए देखें—Character set of C

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

C program to find smallest minimum element in array

#include<stdio.h>
int main()
{
    int num[5],i,small;
    printf("Enter elements of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&num[i]);
    }
    small=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]<small)
        {
            small=num[i];
        }
    }
    printf("Smallest element = %d\n",small);
    return 0;
}

C++ program to find smallest minimum element in array

#include<iostream>
using namespace std;
int main()
{
    int num[5],i,small;
    cout<<"Enter elements of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>num[i];
    }
    small=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]<small)
        {
            small=num[i];
        }
    }
    cout<<"smallst element = "<<small;
    return 0;
}

Output of C C++ program to find smallest minimum element in array

C C++ program to find smallest element in array

Other example programs for array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Reverse Elements of Array
  6. Merging two arrays
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

C C++ program to reverse elements of array

C C++ program to reverse elements of array

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Pointer और इसके कार्य करने के तरीके को आधिक जानने के लिए देखें यह पोस्ट—Pointers in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

C program to reverse elements of array

#include<stdio.h>
int main()
{
    int arr[5],rev[5],i,j=4;
    printf("Enter elements of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<5;i++)
    {
        rev[i]=arr[i];
    }
    for(i=0;i<5;i++)
    {
         arr[i]=rev[j];
         j--;
    }
    printf("Reverse order of array: \n");
    for(i=0;i<5;i++)
    {
        printf("%d ",arr[i]);
    }
    return 0;
 }

C++ program to reverse elements of array

#include<iostream>
using namespace std;
int main()
{
    int arr[5],rev[5],i,j=4;
    cout<<"Enter elements of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<5;i++)
    {
        rev[i]=arr[i];
    }
    for(i=0;i<5;i++)
    {
         arr[i]=rev[j];
         j--;
    }
    cout<<"Reverse order of array: \n";
    for(i=0;i<5;i++)
    {
        cout<<arr[i]<<" ";
    }
    return 0;
 }

Output of C C++ program to reverse elements of array

C CPP program to reverse elements of array

Helpful example program of array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Merging two arrays
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

C C++ program to find largest maximum element in Array

C C++ program to find largest maximum element in Array

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

C program to find largest maximum element in Array

#include<stdio.h>
int main()
{
    int num[5],i,large;
    printf("Enter elements of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&num[i]);
    }
    large=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]>large)
        {
            large=num[i];
        }
    }
    printf("Largest element = %d\n",large);
    return 0;
 }

C++ program to find largest maximum element in Array

#include<iostream>
using namespace std;
int main()
{
    int num[5],i,large;
    cout<<"Enter elements of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>num[i];
    }
    large=num[0];
    for(i=0;i<5;i++)
    {
        if(num[i]>large)
        {
            large=num[i];
        }
    }
    cout<<"Largest element = "<<large;
    return 0;
 }

Output of C C++ program to find largest maximum element in Array

C CPP program to find largest element in Array

Some useful C and C++ array based programs

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Smallest element in Array
  5. Reverse Elements of Array
  6. Merging two arrays
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

C C++ program to find multiplication of two matrix

C C++ program to find multiplication of two matrix

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

Pointer to array क्या होता है जानने के लिए देखें—Pointer to array in C

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

C program to find multiplication of two matrix

#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j,k;
    printf("Enter Values of Matrix 1:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter Values of Matrix 2:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=0;
            for(k=0;k<3;k++)
            {
                r[i][j]=r[i][j]+a[i][k]*b[k][j];
            }
        }
    }
    printf("Multiplication of Matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",r[i][j]);
        }
        printf("\n");
    }
    return 0;
 }

C++ program to find multiplication of two matrix

#include<iostream>
using namespace std;
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j,k;
    cout<<"Enter Values of Matrix 1 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<"Enter Values of Matrix 2 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>b[i][j];
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=0;
            for(k=0;k<3;k++)
            {
                r[i][j]=r[i][j]+a[i][k]*b[k][j];
            }
        }
    }
    cout<<"Multiplication of Matrix:\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cout<<r[i][j]<<"\t";
        }
        cout<<"\n";
    }
    return 0;
 }

Output of C C++ program to find multiplication of two matrix

C C++ program to find multiplication of two matrix

Similar matrix based programs in C C++

  1. Transpose of Matrix
  2. Addition of  two matrix
  3. Sum of elements of matrix
Share it to:

C C++ program to find addition of two matrix

C C++ program to find addition of two matrix

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

C program to find addition of two matrix

#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j;
    printf("Enter Values of Matrix 1:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter Values of Matrix 2:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=a[i][j]+b[i][j];
        }
    }
    printf("Addition of Matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",r[i][j]);
        }
        printf("\n");
    }
    return 0;
 }

C++ program to find addition of two matrix

#include<iostream>
using namespace std;
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j;
    cout<<"Enter Values of Matrix 1 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<"Enter Values of Matrix 2 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>b[i][j];
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=a[i][j]+b[i][j];
        }
    }
    cout<<"Addition of Matrix:\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cout<<r[i][j]<<"\t";
        }
        cout<<"\n";
    }
    return 0;
 }

Output of C C++ program to find addition of two matrix

C C++ program to find addition of two matrix

Other matrix programs in C C++

  1. Transpose of Matrix
  2. Multiplication of two matrix
  3. Sum of elements of matrix
Share it to: