simple display problem??

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

simple display problem??

 
0
  #1
May 16th, 2009
hi,
In my array
arr={10,20,30,40}

i want to display output like
10
20
30
40
10+20
10+30
10+40
20+30
20+40
30+40
10+20+30
10+20+40
20+30+40
10+20+30+40

How to display output like this??
how to do this please help me??
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: simple display problem??

 
0
  #2
May 16th, 2009
Are you sure that you're a software engineer (as described in your profile) ?
  1. 10
  2. 20
  3. 30
  4. 40
(Just display the array)

  1. 10+20
  2. 10+30
  3. 10+40
  4. 20+30
  5. 20+40
  6. 30+40
(Take the first element and display all the elements after it, take the second element and display all the elements after it, take the third element and ...)
Last edited by tux4life; May 16th, 2009 at 4:37 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: simple display problem??

 
-1
  #3
May 16th, 2009
Can You please give me sample code??
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: simple display problem??

 
0
  #4
May 16th, 2009
Originally Posted by Aamit View Post
Can You please give me sample code??
Why should I? If I give you sample code, I'm actually doing your homework, so the answer is (and will always be): NO!
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: simple display problem??

 
0
  #5
May 16th, 2009
int array[] = {10,20,30,40};
find length of array and store in count=4

  1. for (i=0;i<=count;i++)
  2. {
  3. printf("%d",arr[i]);
  4. }
how to move on next step
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: simple display problem??

 
0
  #6
May 16th, 2009
That's already a lot better, you're making progress
To find the length of the array you can do something like this:
const int count=sizeof(array)/sizeof(int); or, if your array is always of the same length: const int count=4;
( const is optional in both cases, but I would recommend it in the second one)

for (i=0;i<=count;i++) has to be: for (i=0;i<count;i++) (otherwise you're overriding the array's bounds)

Now you've already the code to print out the whole array you've already completed 30% of your homework
Last edited by tux4life; May 16th, 2009 at 6:23 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: simple display problem??

 
0
  #7
May 16th, 2009
To achieve the next milestone in your program () the following might help you:
  1. 10+20
  2. 10+30
  3. 10+40
  4. 20+30
  5. 20+40
  6. 30+40
You've to run the loop three times (the number of elements in the array decreased by one)
Every time you display all the elements coming after the element, so if you've 10, you're displaying each time 10+ '20,30,40', for 20 it's the same: 20+ '30,40', and so on
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: simple display problem??

 
0
  #8
May 16th, 2009
For the third part:
  1. 10+20+30 => all elements except the last one
  2. 10+20+40 => all elements except the one before the last one
  3. 20+30+40 => all elements except the first one
  4. 10+20+30+40 => all elements
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: simple display problem??

 
0
  #9
May 16th, 2009
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. printf("hello");
  6. int arr[] = {10,20,30,40};
  7. int count=sizeof(arr)/sizeof(int);
  8. int i,j;
  9. for (i=0;i<count;i++)
  10. {
  11. printf("%d",arr[i]);
  12. printf("\n");
  13. for(j=i+1;j<count;j++)
  14. {
  15. printf("%d + %d",arr[i],arr[j]); printf("\n");
  16. }
  17.  
  18. }
  19. getch();
  20. }
but problem is how to make this dynamic??
or display all numbers
Last edited by Ancient Dragon; May 16th, 2009 at 8:20 am. Reason: fix code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 794
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: simple display problem??

 
0
  #10
May 16th, 2009
>>but problem is how to make this dynamic??
What do you mean by dynamic?

BTW, do you realize that the code which you have written is no where near to c++?
This is a C code. And you participate in a C++ forum. No doubt you have a red dot on the reputation bar.
C++ is not C. There is a hell lot of difference between these two language.
You should start learning C++. Buy some books like Accelerated C++
and learn the language first.
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C Forum


Views: 1942 | Replies: 30
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC