Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me find code for two programs in C++

Status
Not open for further replies.

yousefsam

Member level 1
Member level 1
Joined
May 18, 2006
Messages
37
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Activity points
1,569
help me plz in C++

Plz help me to find the solution of two programs in C++:
1. program to creat array and save the values in it , and save the factorial of those values into another one (Using Array) .
2. program to creat a binary search.
 

Re: help me plz in C++

Although this souds very much like homework you can try to do a search for some pseudo code. That should help greatly in the implementation of the actual application.

If you only need some language semantics google is also a great help.

Cheers
Slayer
 

Re: help me plz in C++

plz can you solve the first question.
 

Re: help me plz in C++

Ok here goes for the first question I'm going to assume that the user enters several values. Say 5. The values are stored in an array and then the factorial is computed and stored in another array.

Code:
#include <iostream>
using namespace std;

//declare factorial prototype
//no implementation is provided.
long factorial (int number); //maybe needs to be float etc.

//start of main program

void main (void)
{
 int i = 0;  //initialize a loop counter
 int user_values[5] = 0; //define input array
 long user_factorial[5] = 0; //define outut array

 for (i = 0; i < 5; i++)
 {
  cout<<"Enter some number ";
  cin>>user_values[i]; //read the user value
  cout<<newline;
  user_factorial[i] = factorial(user_values[i]); //calculate and store factorial
 }
return;
} //end main



Than should solve the problem however some remarks,
1. Assumed that only 5 values are entered -> if unknown assign dynamic
2. NO error or range checking are performed.

Hope this helps
Slayer

P.S - Code may contain errors but logically it is OK
 

Re: help me plz in C++

If you found the information helpful click the "Helped Me" button in my post.

Cheers
Slayer
 

    yousefsam

    Points: 2
    Helpful Answer Positive Rating
Re: help me plz in C++

AFAIK the second problem of the binary search requires that the data be sorted eiter ascending or decending. The basic concept then becomes starting at the centre determine if the desired value is above or below that. In either case move your reference point by half way and repeat until the desired information is found. Just make sure that the loop can exit if the data is indeed not in the list.

If you need some more help, just ask.

Cheers
Slayer
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top