473,387 Members | 3,787 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,387 software developers and data experts.

Array problem in C Programming.

7
1) Write a C program that declares an integer array with 5 elements.
2) Inside a for() loop ask the user for a number and store it in the first element of the array (numerically the array is indexed from zero).
3) Your loop will iterate 5 times and each time you get a number you will fill up the next spot in the list. After 5 pieces of data have been entered your array will be full.
4) Write a second for() that looks at what is in the list. Find the largest number in the array. Print that number when you find it.

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

Sample Output

Enter a number: 1234
Enter a number: -444
Enter a number: 900
Enter a number: 3
Enter a number: 2
The largest number in the list is 1234

Enter a number: -100
Enter a number: -3
Enter a number: -4
Enter a number: -2
Enter a number: -44
The largest number in the list is -2

-------------------------------------------------------------------------------------------------------------------
Nov 10 '06 #1
5 4539
KhzQas
7
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.  int list[5];
  6.  int i;
  7.  int number;
  8.  
  9.  for (i = 0; i < 5; i++)
  10.  {
  11.   printf("Enter a number: ");
  12.   scanf("%d", &number);
  13.  
  14.   list[i] = number;
  15.  
  16.  }
  17. return 0;
  18. }
The above is the programming code that I have written to so far. I can not get to the 4th point for some reason, the one where I have to create another for() loop to find the largest value in the array list. Any help would greatly be appreciated.
Nov 10 '06 #2
HI ,
This is the code for to find the largest number in the array .This code is executed.Hope this will help others .

//code goes here

//code has been removed
//MODERATOR
Jan 12 '08 #3
Laharl
849 Expert 512MB
@nswathi: Please don't spoonfeed code.

@OP: If you haven't already seen the code above, how would you do it if you were the computer? What steps would you take to determine the largest element?
Jan 12 '08 #4
@nswathi: Please don't spoonfeed code.

@OP: If you haven't already seen the code above, how would you do it if you were the computer? What steps would you take to determine the largest element?
may i know the reason
Jan 22 '08 #5
Laharl
849 Expert 512MB
may i know the reason
To why we don't spoonfeed code here? So that people learn why the code works, as opposed to blindly feeding someone else's code into their work. Read the Posting Guidelines and the Coursework Posting Guidelines for more information.
Jan 22 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William | last post by:
I would appreciate your help on the following programming questions: 1. Given an array of length N containing integers between 1 and N, determine if it contains any duplicates. HINT: The...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
12
by: Uncle | last post by:
I am an untrained hobbyist. Everything about programming I have learned from the internet. Thank you all for your gracious support. This is what I have: #define CONST_CHAR 0 void some_func(...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
7
by: arnuld | last post by:
this programme gives unusual output. i am not able to find out where the semantic bug lies: /* C++ Primer - 4/e * * an example from section section 7.2.4, page 241 * STATEMENT * write a...
5
by: benyboy | last post by:
hi, after hours of staring at my computer screen, and browsing through various internet forums i am totally stuck! I have created the following array which reads from an input file the following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.