944,161 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2809
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 7th, 2005
0

pls i need help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
umbrella is offline Offline
2 posts
since Aug 2005
Aug 7th, 2005
0

Re: pls i need help

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Aug 7th, 2005
0

Re: pls i need help

Quote 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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
umbrella is offline Offline
2 posts
since Aug 2005
Aug 7th, 2005
0

Re: pls i need help

How about for each number, you save it if it's bigger than the last one?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Aug 7th, 2005
0

Re: pls i need help

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!
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Aug 8th, 2005
0

Re: pls i need help

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. }
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
Aug 8th, 2005
0

Re: pls i need help

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.
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Aug 9th, 2005
0

Re: pls i need help

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.
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
Aug 9th, 2005
0

Re: pls i need help

It's actually less readable and less user friendly because every other C/C++ programmer starts arrays at zero.
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Aug 9th, 2005
0

Re: pls i need help

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:
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: Global Variables help
Next Thread in C Forum Timeline: Please help with program - STUCK





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC