pls i need help

Closed Thread

Join Date: Aug 2005
Posts: 2
Reputation: umbrella is an unknown quantity at this point 
Solved Threads: 0
umbrella umbrella is offline Offline
Newbie Poster

pls i need help

 
0
  #1
Aug 7th, 2005
hi to all.. i need help about C programming i have problem with my project, its about that how to determine the max number using for loop ill give the output and pls give me the code plss
Output:
Enter Numbers: 5<--input
Enter first number:1<--input
Enter second number:2<--input
Enter third numbe:3<--input
Enter fourth number:4<--input
Enter fifth number:5<--input
Maximum number is: 5<---result
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: pls i need help

 
0
  #2
Aug 7th, 2005
>pls give me the code plss
No, no, and no. We don't do homework, and the more you ask, the more we will consider banning you. If you want to post an honest attempt to solve the problem, we'll be glad to help you with it, but we won't do it for you.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Aug 2005
Posts: 2
Reputation: umbrella is an unknown quantity at this point 
Solved Threads: 0
umbrella umbrella is offline Offline
Newbie Poster

Re: pls i need help

 
0
  #3
Aug 7th, 2005
Originally Posted by Narue
>pls give me the code plss
No, no, and no. We don't do homework, and the more you ask, the more we will consider banning you. If you want to post an honest attempt to solve the problem, we'll be glad to help you with it, but we won't do it for you.
ok sir just give me a tip i know it is for loop but my problem is how to determine the max number...
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: pls i need help

 
0
  #4
Aug 7th, 2005
How about for each number, you save it if it's bigger than the last one?
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: pls i need help

 
0
  #5
Aug 7th, 2005
how would you do it in your head especially if you had a poor memory.
You would loop through your list, examine first number and write it down on a bit of paper.Then you would look at next number if there was one and if bigger you would scrub out whats on the slip of paper and write the new number down. Eventually you would have examined all the numbers and the number on the paper slip will be the biggest number in the collection. Now if you cant figure out how to convert that to c++ dont fear, theres always a call for refuse collectors!
Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Re: pls i need help

 
0
  #6
Aug 8th, 2005
okay umbrella here is your code.this will find the largest number in a given set of numbers.first of all you store the given numbers in an array and then initialise a for loop:-

  1. main()
  2. {
  3. int i,j,max,a[100];
  4. printf("\enter the number of elements");
  5. scanf("%d",&i);
  6. for(j=1;j<=i;j++)
  7. {
  8. printf("enter the %d element",j);/*comparing and finding the largest number*/
  9. scanf("%d",&a[j]);
  10. }
  11. max=a[1];
  12. for(j=1;j<=i;j++)
  13. {
  14. if(a[j]>max)
  15. max=a[j];
  16. }
  17. printf("\nthe largest number among the given set of numbers is %d",max);
  18. }
Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: pls i need help

 
0
  #7
Aug 8th, 2005
indian scorpion dont you like array[0] for some reason. remember in c/c++ arrays are zero based not 1 based.Its possible for that prog to segfault. Also its not a good idea to give homework answers if the OP has shown no effort especially flawed ones.
Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Re: pls i need help

 
0
  #8
Aug 9th, 2005
mr.stoned_coder for your information.the code is executing perfectily.and i have started the counting from 1 so that the program looks more readable and user friendly.
Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: pls i need help

 
0
  #9
Aug 9th, 2005
It's actually less readable and less user friendly because every other C/C++ programmer starts arrays at zero.
Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: pls i need help

 
0
  #10
Aug 9th, 2005
Ok so you wanna look like a dick!
  1. scanf("%d",&i);
  2. for(j=1;j<=i;j++)
  3. {
  4. printf("enter the %d element",j);/*comparing and finding the largest number*/
  5. scanf("%d",&a[j]);
  6. }
enter 100
j<=100, 100 is <= 100 so code executes
scanf("%d",&a[100]).... segfault
a[99] is the last element of the array.
:cheesy: :cheesy:
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC