Function Programming : Print Array in C

Write a C Program to print all elements from an Array using c-function.

#include<stdio.h>
void array(int b[], int n);
int main( )
{
     int n, j;
     printf("\nThe size of array is : ");
     scanf("%d", &n);
     int a[n];
     printf("\nInsert your values: ");
     for(j=0; j<n; j++)
          scanf("%d", &a[j]);
     array(a, n);
}

void array(int b[],int n)
{
      int i;
      printf("\nYour values are: ");
      for(i=0; i<n; i++)
           {
                 printf("  %d", b[i]);
           }
}

21 comments:

  1. #include
    main()
    {
    int n,j;
    printf("The size of array is : ");
    scanf("%d",&n);
    int a[n];
    array(a,n);
    printf("\nYour values are : ");
    for(j=0;j<n;j++)
    printf("\n%d",a[j]);
    }

    int array(int b[],int n)
    {
    int i;
    printf("\nEnter your values : \n");
    for(i=0;i<n;i++)
    {
    scanf("%d",&b[i]);
    }
    }

    ReplyDelete
  2. #include
    int arr(int a[],int len);
    main()

    {
    int m,t;
    printf("Enter the array size : ");
    scanf("%d",&m);
    int a[m];
    arr(a,m);
    printf("Values are :");
    for(t=0;t<m;t++)
    printf("\n%d",a[t]);
    }

    int arr(int b[],int k)

    {
    int i;
    printf("Enter the values : \n");
    for(i=0;i<k;i++)
    scanf("%d",&b[i]);
    }

    ReplyDelete
  3. #include
    main()
    {
    int n,j;
    printf("The size of array is : ");
    scanf("%d",&n);
    int a[n];
    array(a,n);
    printf("\nYour values are : ");
    for(j=0;j<n;j++)
    printf("\n%d",a[j]);
    }

    int array(int b[],int n)
    {
    int i;
    printf("\nEnter your values : \n");
    for(i=0;i<n;i++)
    {
    scanf("%d",&b[i]);
    }
    }

    ReplyDelete
  4. #include
    #include
    int print_array(int a[], int n);
    int main()
    {
    int n,result,i;
    printf("\n Enter array size; ");
    scanf("\n%d",&n);
    int a[n];
    result=print_array(a,n);
    i=0;
    do
    {
    printf("\n%d",a[i]);
    i++;
    }while(i<n);
    getch();
    return 0;
    }

    int print_array(int a[],int n)
    {
    int j;
    printf("\nEnter values");
    j=0;
    do
    {
    scanf("\n %d",&a[j]);
    j++;
    }while(j<n);

    printf("\n your values are");

    }

    ReplyDelete
  5. #include
    #include
    int print_array(int a[], int n);
    int main()
    {
    int n,result,i;
    printf("\n Enter array size; ");
    scanf("\n%d",&n);
    int a[n];
    result=print_array(a,n);
    for(i=0;i<n;i++)
    {
    printf("\n%d",a[i]);

    }
    getch();
    return 0;
    }

    int print_array(int a[],int n)
    {
    int j;
    printf("\nEnter values");

    for(j=0;j<n;j++)
    {
    scanf("\n %d",&a[j]);

    }

    printf("\n your values are");

    }

    ReplyDelete
  6. #include
    #include
    int print_array(int a[], int n);
    int main()
    {
    int n,result,i;
    printf("\n Enter array size; ");
    scanf("\n%d",&n);
    int a[n];
    result=print_array(a,n);
    i=0;
    do
    {
    printf("\n%d",a[i]);
    i++;
    }while(i<n);
    getch();
    return 0;
    }

    int print_array(int a[],int n)
    {
    int j;
    printf("\nEnter values");
    j=0;
    while(j<n)
    {
    scanf("\n %d",&a[j]);
    j++;
    }

    printf("\n your values are");

    }

    ReplyDelete
  7. Md. Rajib Sarker Id. 201320635December 12, 2013 at 10:13 PM

    #include
    int arr(int a[],int len);
    main()

    {
    int m,t;
    printf("Enter the array size : ");
    scanf("%d",&m);
    int a[m];
    arr(a,m);
    printf("Values are :");
    for(t=0;t<m;t++)
    printf("\n%d",a[t]);
    }

    int arr(int b[],int k)

    {
    int i;
    printf("Enter the values : \n");
    for(i=0;i<k;i++)
    scanf("%d",&b[i]);
    }

    ReplyDelete
  8. #include
    #include
    int funcx(int n[],int s);
    int main()
    {
    int n,result,j;
    printf("\n Enter size:");
    scanf("%d",&n);
    int a[n];
    result=funcx(a,n);
    for(j=0;j<n;j++)
    {
    printf("\n %d",a[j]);
    }
    getch();
    return 0;


    }

    int funcx(int n[],int s)
    {
    int i;
    printf("\n Enter values:");
    for(i=0;i<s;i++)
    {
    scanf("\n %d",&n[i]);
    }
    printf("\n enter values are:");
    }

    ReplyDelete
  9. #include
    int print_an_array(int a[10])
    {
    return a[10];
    }
    main()
    {
    int i;
    int a[10]={1,2,3,4,5,6,8,9,10};
    for(i=1;i<=10;i++)
    {
    printf("\n%d",print_an_array(a));
    }
    }

    ReplyDelete
  10. #include
    main()
    {
    int a,b=5;
    scanf("%d",& a);
    number(a,b);
    }
    int number(int c,int d)
    {
    if(c%d==0)
    printf("The number is divisible by 5");
    else
    printf("Thr number is not by 5");
    }

    ReplyDelete
  11. #include

    int printArray(int b[],int n)
    {
    int i;
    printf("\nEnter your values : \n");
    for(i=0; i<n; i++)
    {
    scanf("%d",&b[i]);
    }
    }

    int main()
    {
    int n,j;
    printf("The size of array is : ");
    scanf("%d",&n);
    int a[n];
    printArray(a,n);
    printf("\nYour values are : ");
    for(j=0; j<n; j++){
    printf("\n%d",a[j]);
    }
    }

    ReplyDelete
  12. #include
    using namespace std;
    class Array

    {
    public:
    int n;
    Array ();
    void output();
    ~Array();
    };
    Array::Array()
    {
    cout<<"Enter how many to hold in Array:"<>n;
    }
    void Array::output()
    {
    int arr[n],i,j;
    cout<<"Enter"<>arr[i];
    cout<<"The Array is:";
    for(j=0;j<n;j++)
    cout<<arr[j]<<endl;
    }
    Array::~Array()
    {

    }
    int main()
    {
    Array obj;
    obj.output();
    return 0;
    }

    ReplyDelete
  13. #include
    using namespace std;

    class Array
    {
    public:
    int n;
    Array();
    void process();
    ~Array();
    };
    Array::Array()
    {
    cout<<"Enter how many number do u want: ";
    cin>>n;
    }
    void Array::process()
    {
    int i,arr[n];
    cout<<"Enter values in the array: ";
    for(i=0;i>arr[i];
    cout<<"Printing the array: ";
    for(i=0;i<n;i++)
    cout<<endl<<arr[i];
    }
    Array::~Array()
    {
    cout<<endl<<"Destructing....";
    }
    main()
    {
    Array ob;
    ob.process();
    }



    ReplyDelete
  14. #include
    using namespace std;
    class Array
    {
    public:
    int n;
    Array();
    void output();
    ~Array();
    };
    Array::Array()
    {
    cout<<"Enter how many numbers to hold in array: ";
    cin>>n;
    cout<>arr[i];
    cout<<"The array is: "<<endl;
    for(j=0; j<n; j++)
    cout<<arr[j]<<endl;
    }
    Array::~Array()
    {

    }
    int main()
    {
    Array obj;
    obj.output();
    return 0;
    }

    ReplyDelete
  15. #include
    using namespace std;

    class cons
    {
    public:
    int num;
    cons(int i);
    void result();
    ~cons();
    };

    cons::cons(int i)
    {
    num = i;
    }

    void cons::result()
    {
    int arr[num], j;
    cout << "Enter your array element --: ";
    for (j = 0; j < num; j++)
    cin >> arr[j];
    cout << "\nYour array element is --: ";
    for (j = 0; j < num; j++)
    cout << arr[j] << "\t";
    }

    cons::~cons()
    {
    cout << "\n[+]MEMORY RELEASED[+]";
    }

    int main()
    {
    int j;

    cout << "Enter how many element in your array --: ";
    cin >> j;

    cons obj(j);
    obj.result();

    return 0;
    }
    id 201510505
    batch48

    ReplyDelete
  16. #include
    using namespace std;
    class Array
    {
    public:
    int n;
    Array();
    void output();
    ~Array();
    };
    Array::Array()
    {
    cout<<"Enter how many numbers to hold in array: ";
    cin>>n;
    cout<>arr[i];
    cout<<"The array is: "<<endl;
    for(j=0; j<n; j++)
    cout<<arr[j]<<endl;
    }
    Array::~Array()
    {

    }
    int main()
    {
    Array obj;
    obj.output();
    return 0;
    }

    ReplyDelete
  17. #include
    #include

    using namespace std;
    class arr
    {
    public:
    int n;
    arr();
    void show();

    };
    arr::arr()
    {
    cout<<"Input arry size: ";
    cin>>n;
    }
    void arr::show()
    {
    char a[n];
    for(int i=0;i<n;i++)
    gets(a);
    for(int i=0;i<n;i++)
    puts(a);

    }
    int main()
    {
    //int n;
    //cout<<"Input arry size: ";
    arr ob;
    ob.show();

    }

    ReplyDelete
  18. using C++

    #include
    using namespace std;

    class cons
    {
    public:
    int num;
    cons(int i);
    void result();
    ~cons();
    };

    cons::cons(int i)
    {
    num = i;
    }

    void cons::result()
    {
    int arr[num], j;
    cout << "Enter your array element --: ";
    for (j = 0; j < num; j++)
    cin >> arr[j];
    cout << "\nYour array element is --: ";
    for (j = 0; j < num; j++)
    cout << arr[j] << "\t";
    }

    cons::~cons()
    {
    cout << "\n[+]MEMORY RELEASED[+]";
    }

    int main()
    {
    int j;

    cout << "Enter how many element in your array --: ";
    cin >> j;

    cons obj(j);
    obj.result();

    return 0;
    }

    ReplyDelete
  19. #include
    using namespace std;
    class arr
    {
    public:
    int num,i;
    arr();
    ~arr()
    {
    cout<>a[i];
    cout<<"Your array numbers are: "<>num;
    }
    int main()
    {
    arr obj;
    obj.func();
    return 0;
    }

    id:201510660

    ReplyDelete
  20. #include
    using namespace std;
    class arr
    {
    public:
    int num,i;
    arr();
    ~arr()
    {
    cout<>a[i];
    cout<<"Your array numbers are: "<>num;
    }
    int main()
    {
    arr obj;
    obj.setu();
    return 0;
    }

    id:201510992

    ReplyDelete
  21. using c++

    #include
    using namespace std;

    class cons
    {
    public:
    int num;
    cons(int i);
    void result();
    ~cons();
    };

    cons::cons(int i)
    {
    num = i;
    }

    void cons::result()
    {
    int arr[num], j;
    cout << "Enter your array element --: ";
    for (j = 0; j < num; j++)
    cin >> arr[j];
    cout << "\nYour array element is --: ";
    for (j = 0; j < num; j++)
    cout << arr[j] << "\t";
    }

    cons::~cons()
    {
    cout << "\n[+]MEMORY RELEASED[+]";
    }

    int main()
    {
    int j;

    cout << "Enter how many element in your array --: ";
    cin >> j;

    cons obj(j);
    obj.result();

    return 0;
    }

    ReplyDelete