Write a C++ program that initialize 10 values in arrays. Your program asks a number from user.

Write a program that initialize 10 values in arrays. Your program asks a number from user and prints all location where number is present.initialize 10 values in arrays

#include <iostream>
using namespace std;
int main()
{
    int arr[10] = { 34,4,43,43,45,44,1,4,6 };
    int n, i;
    //take input from user
    cout << "Enter value : ";
    cin >> n;
    //using for loop
    for (i = 0; i < 10; i++)
    {
        //if statement
        if (n == arr[i])
        {
            cout << " Number " << n << " is present in index : " << i << endl;
        }
    }
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *