Give me the explanation for this output

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 1
Reputation: suganthan901307 is an unknown quantity at this point 
Solved Threads: 0
suganthan901307 suganthan901307 is offline Offline
Newbie Poster

Give me the explanation for this output

 
-5
  #1
19 Days Ago
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int x[5]={1,2,3,4,5},y[5]={5,4,3,2,1},result [5]={0,0,0,0,0};
  6. int i=0;
  7. while(i++ <5)
  8. result[i]=x[i]-y[i];
  9. clrscr();
  10. cout<<"\nThe contents of the array are :\n";
  11. i=0;
  12. do
  13. {
  14. cout<<'\t'<<x[i]<<'\t'<<y[i]<<'\t'<<result [i]<<"\n";
  15. i++;
  16. }while(i<5);
  17. getch();
  18. }
OUTPUT:

The contents of the array are:

1 -1 0
2 4 -2
3 3 0
4 2 2
5 1 4
GIVE ME THE EXPLANATION FOR THIS OUTPUT.
e-mail to <EMAIL SNIPPED>
Last edited by peter_budo; 19 Days Ago at 5:02 am. Reason: Keep It On The Site - Do not post asking for an answer to be sent to you via email or PM.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,336
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
0
  #2
19 Days Ago
the output you posted is wrong. Here is the correct output. Had you bothered to compile and run that program you would have seen it too.

  1.  
  2. The contents of the array are :
  3. 1 5 0
  4. 2 4 -2
  5. 3 3 0
  6. 4 2 2
  7. 5 1 4
Last edited by Ancient Dragon; 19 Days Ago at 10:28 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC