470,810 Members | 861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Please help me in this

Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.
Hints
∑ There is an integer variable value and an array test[] of size 10.
∑ Pass the array to the find() function by reference but pass the
variable value by value.
∑ The function find() takes two parameters (i.e. an integer array and
an integer variable value) but returns no value (i.e. void).
Sample Output

Enter values into array
17
21
34
31
44
23
78
21
66
35
Enter a value to be searched: 23
The element was found and the location is 6

Enter values into array
29
22
36
30
54
63
78
21
26
85
Enter a value to be searched: 23
The element was not found.

May 13 '06 #1
10 1400
na**********@gmail.com wrote:
Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.
Hints
· There is an integer variable value and an array test[] of size 10.
· Pass the array to the find() function by reference but pass the
variable value by value.
· The function find() takes two parameters (i.e. an integer array and
an integer variable value) but returns no value (i.e. void).
Sample Output

Enter values into array
17
21
34
31
44
23
78
21
66
35
Enter a value to be searched: 23
The element was found and the location is 6
g
Enter values into array
29
22
36
30
54
63
78
21
26
85
Enter a value to be searched: 23
The element was not found.


Send me a reasonable fee and I will do your homework for you.

But if I did that for such a lazy person as you seem to be, you would NEVER
learn anything - except how to copy your homework question into a
newsgroup.

Why don't you at least try to do something, even if your programming skills
are very basic, and post the code here if you get into trouble. Then we
can try to help you.

You never know, you may even learn something :D

Alan
May 13 '06 #2

<na**********@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Re: Please help me in this Write a program that will


.... etc.

Sure we'll help you with your program, but
we need to see it. You also need to tell us
what problems you're having (e.g. compiler
errors, program behaves other than expected, etc.)

-Mike


May 13 '06 #3
Mike Wahler wrote:

<na**********@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Re: Please help me in this

Write a program that will


... etc.

Sure we'll help you with your program, but
we need to see it. You also need to tell us
what problems you're having (e.g. compiler
errors, program behaves other than expected, etc.)

-Mike


Problem is, Mike, for us to see his program he first has to write it!!

Also you use the word "compiler" without explaining to him just what a
compiler is.

He is probably better off changing his course to Needlework or Knitting

Alan
May 13 '06 #4
na**********@gmail.com wrote:

I suggest you start by making a "Hello world" program and concentrate on
making it compile before you begin with such more "advanced" questions.
Best regards / Med venlig hilsen
Martin JÝrgensen

--
---------------------------------------------------------------------------
Home of Martin JÝrgensen - http://www.martinjoergensen.dk
May 13 '06 #5
<na**********@gmail.com> wrote:

in message news:11**********************@j73g2000cwa.googlegr oups.com...
Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.
Hints
∑ There is an integer variable value and an array test[] of size 10.
∑ Pass the array to the find() function by reference but pass the
variable value by value.
∑ The function find() takes two parameters (i.e. an integer array and
an integer variable value) but returns no value (i.e. void).

I don't like hint number 2. How about ignoring that hint and trying to write
the program? Hints are supposed to be helpful and one should be entitled to
pretend they don't exist.

Also, try as I might, I can find no information content in hint number 1. So
feel free to ignore it, too. I suspect your instructor thinks that "hint"
and "summary" are pretty much synonyms.
May 13 '06 #6
"osmium" writes:
<na**********@gmail.com> wrote:

in message news:11**********************@j73g2000cwa.googlegr oups.com...
Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.
Hints
∑ There is an integer variable value and an array test[] of size 10.
∑ Pass the array to the find() function by reference but pass the
variable value by value.
∑ The function find() takes two parameters (i.e. an integer array and
an integer variable value) but returns no value (i.e. void).

I don't like hint number 2. How about ignoring that hint and trying to
write the program? Hints are supposed to be helpful and one should be
entitled to pretend they don't exist.

Also, try as I might, I can find no information content in hint number 1.
So feel free to ignore it, too. I suspect your instructor thinks that
"hint" and "summary" are pretty much synonyms.


This piece of crap OE messed up and left off the attribution > . It's not
my fault.
May 13 '06 #7
osmium wrote:
This piece of crap OE messed up and left off the attribution > . It's not
my fault.


<newsreader advocacy>
How about Thunderbird?
</newsreader advocacy>
Jonathan

May 13 '06 #8
na**********@gmail.com wrote:
Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.


Here is your homework for you! When you write back to say "thank you"
please let us know how much you have learned from me doing your work for
you.

Programming requires intelligence, hard work and initiative - I suspect you
lack all of these. Why don't you try Needlework, Knitting or something
more suitable to your capacity.

Just print out the following and hand it to your teacher.

----------------------------------------------------------------

/*
Program: MyHomework.c
Programmer: Alan L Brown, Wagga Wagga, NSW, Australia
Date: Sunday May 4, 2006
Compiler: GCC 4.0.0 (tested with C and C++ compilers)
also runs under Borland C++ under Windows 98SE
System: Linux 2.6.11
*/

#include <stdio.h>

//Global constant
const int MAX = 10; //Maximum elements in array "test"

//Function Prototype
//Function to search for "element" in the array "test"
void find (int [], int);

int main(void)
{
int i,
element, //Input "element" for search
test[10]; //Array of input numbers

printf("Enter values into array\n");

//Fill array with input values
for (i = 0; i < MAX; i++)
scanf("%d", &test[i]);

printf("Enter a value to be searched: ");
scanf("%d", &element); //Enter the search Value
find(test, element); //Search for "element" in the array "test"
}

//Function to search for "element" in the array "test"
void find (int test[], int element)
{
int i;
for (i = 0; i < MAX; i++)
{
//Test to see if "element" is in the array "test"
if (test[i] == element)
{
printf("The element was found and the location is %d\n\n", i + 1);
return; //"element" found - return
}
}
printf("\nThe element was not found.\n\n");
return; //"element" NOT found - return
}

---------------------------------------------------------------------------
May 14 '06 #9
Alan <i.****@octopus.com.au> wrote:
na**********@gmail.com wrote:
Write a program that will define an integer array test[] of size 10.
The program will read values into the array test[] through keyboard
from the user. After reading into the array test[] the program will
prompt the user to "Enter a value to be searched:". In response,
the user will enter a value through keyboard and the program will store
the value in an integer variable value. The program will then pass the
array test[] and the variable value to a function find(). The function
find() will search the array test[] for the given element value. If the
element was found then a message "The element was found and the
location is "is displayed. If the element was not found then a
message "The element was not found." is displayed. The result is
displayed in the find() function.


Here is your homework for you! When you write back to say "thank you"
please let us know how much you have learned from me doing your work for
you.

Programming requires intelligence, hard work and initiative - I suspect you
lack all of these. Why don't you try Needlework, Knitting or something
more suitable to your capacity.

Just print out the following and hand it to your teacher.

----------------------------------------------------------------

/*
Program: MyHomework.c
Programmer: Alan L Brown, Wagga Wagga, NSW, Australia
Date: Sunday May 4, 2006
Compiler: GCC 4.0.0 (tested with C and C++ compilers)
also runs under Borland C++ under Windows 98SE
System: Linux 2.6.11
*/

#include <stdio.h>

//Global constant
const int MAX = 10; //Maximum elements in array "test"

//Function Prototype
//Function to search for "element" in the array "test"
void find (int [], int);

int main(void)
{
int i,
element, //Input "element" for search
test[10]; //Array of input numbers

printf("Enter values into array\n");

//Fill array with input values
for (i = 0; i < MAX; i++)
scanf("%d", &test[i]);

printf("Enter a value to be searched: ");
scanf("%d", &element); //Enter the search Value
find(test, element); //Search for "element" in the array "test"
}

//Function to search for "element" in the array "test"
void find (int test[], int element)
{
int i;
for (i = 0; i < MAX; i++)
{
//Test to see if "element" is in the array "test"
if (test[i] == element)
{
printf("The element was found and the location is %d\n\n", i + 1);
return; //"element" found - return
}
}
printf("\nThe element was not found.\n\n");
return; //"element" NOT found - return
}

---------------------------------------------------------------------------

// Why not:
#define MAX 10
// and use it in the definition of test[]
int test[MAX]
// also
scanf("%d", &test[i]); // the ampersand is redundant
// might be nice to allow the user to search more than once
May 15 '06 #10
Gilbert Smith wrote:
< [..]
// Why not:
#define MAX 10
Because it is better to use a typed constant than a macro.
// and use it in the definition of test[]
int test[MAX]
You can use the const here just as well.
// also
scanf("%d", &test[i]); // the ampersand is redundant
No, it is not. If you drop the ampersand, you need to rewrite
the expression to make it an address again.
// might be nice to allow the user to search more than once


Might be.

V
--
Please remove capital As from my address when replying by mail
May 15 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by HolaGoogle | last post: by
3 posts views Thread by Mark Broadbent | last post: by
9 posts views Thread by FERHAT A«ICI | last post: by
31 posts views Thread by Simply_Red | last post: by
4 posts views Thread by ssniit | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.