Go4Expert (http://www.go4expert.com/)
-   Meet and Greet (http://www.go4expert.com/community/meet-and-greet/)
-   -   arrays in c++ (http://www.go4expert.com/community/arrays-in-cpp-t22925/)

arlitch 4Aug2010 10:30

arrays in c++
  1. To execute inputting in a 1 dimensional array using recursion, and check if the input already occurs.
  2. To implement counting and displaying of the prime numbers and numbers with n factor
Procedure:Write this program in C++
  1. Declare a long int variable of array composed of 10 elements and initialize all the contents into zero.
  2. Ask for 10 inputs in which each input i is 1<i<65000, then check the occurences of i in the array, if it already occurs, do not place it in the array, hence ask for another input on that same index location.
  3. When all the 10 elements of the array are already filled with 10 values for each index, Implement the screen 1 below.
  4. On Option 1, count and display all the prime numbers contained in the array. Goto # 7 if the user would still like to continue.
  5. On Option 2, count and display all the numbers contained in the array with the factor n that you'll input, wherein 2<n<65000. Goto # 7 if the user would still like to continue.
  6. If neither 1, nor 2 is pressed, repeat procedure 3.
  7. Prompt the user with (Y/y or press any key to exit) if s/he would like to continue or not.
Screen # 1:

1. Count and display the number of prime numbers
2. Count and display the number of with n factor

Enter and option (either 1 or 2):

help me please!!!!!:embarasse

Cris Dcst 17Aug2012 11:49

Re: arrays in c++

#include <iostream.h>
#include <conio.h>
void main()

long int array[10] = {0,0,0,0,0,0,0,0,0,0};
int i, ctr1=0, flag,k,j;
char option,o;

    for (i=0; i<=10; i++)
            cout<<"Enter input number(s)["<<i<<"]:";
            if (i>0) {
                for (int k=i-1; k>=0; k--)
                    if  (array[k]==array[i]){
                                cout<<"The input value already occurs!\n";
                                goto loop;
    cout<<"Enter an option (either 1 or 2):";

        if (option=='1')  {

                cout<<"Prime number(s):\n";
                    for (i=0; i<=5; i++)
                            for (int j=2; j<=array[i]/2;j++)
                                    if (array[i]%j==0)
                                    cout<<array[i]<<" ";

                            if (flag==0)

                      cout<<array[i]<<" ";
                cout<<"\nNumbers of prime numbers entered:\n"<<ctr1<<endl;
                cout<<"Would you like to comtinue? y/n";
                cin>>o;    }

        cout<<"Program Terminated:\n" ;


:charming: quite easy.. hope you appreciate

All times are GMT +5.5. The time now is 22:36.