TRAVERSING AN ARRAY

//there is a simple program that will print all elements of an array

language=C++

#include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int n,number = 0;

    cout << "Enter number of elements?";

    cin >>n;


    int la[n];

    for(int i = 0; i < n; i++)
    {
        char c;

        scanf( "%d%c",&la[i],&c );

        number += 1;

        if(c == '\n')
        {
            break;
        }
    }

    for(int i = 0; i < number; i++)
        cout << la[i] << " ";

    return 0;

}


No comments:

Post a Comment

Kruskal Algorithm

Minimum Cost Spanning Tree By Kruskal Algorithm using priority_queue in c++ #include<bits/stdc++.h> using namespace std; typedef p...