473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1539
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KK | last post by:
Hi Peoples, Can anyone give me any learning materials for learning C++. i.e. can you give me any docs or give me the link to any website that has info on programming in general or C++. (ok...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
3
by: Mark Broadbent | last post by:
could somebody please recommend a good book to prepare for exam Exam 70-320*: Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework . One that...
9
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
31
by: Simply_Red | last post by:
i'm sorry i posted this in other groupes, and i didn't see it, and as this group is most actif, i repost it here, and sorry for mutliposting: Hi, i'm using VC6, i have this declaration: ...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
2
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
4
by: ssniit | last post by:
Please can anyone help me with d programs in C for treat the matter most urgent please please please please .................................! CPU scheduling: WAP to show FCFS scheduling...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.