Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 12th, 2012, 03:21 PM
Bloodyred Bloodyred is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 Bloodyred User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 10 sec
Reputation Power: 0
-858993460 Value when use prinft, please help

Hi, i'm starting with my course of Structured programming and i'm programming in C, so, here i am in Microsoft Visual C++ 2010 making this program of print an array of 20 numbers in order and backwards, but when the backward array is printed it shows "-858993460" in the first value and i don't know why the program do this, i would like you to help me to solve this and a little explanation of why and what can i do for avoid it in the future.

Here is the code and the result:
Code:
#include <stdio.h>
#include <conio.h>

int main()
{
	
	int Items[20];
	int i;
	puts("introduce 20 numbers, followed by return");

	for (i=0; i<20; i++)
		scanf("%d", &Items[i]);
	
	for (i=0; i<20; i++)
	printf("%d ",Items[i]);
	printf("\n");
	
	for (i=20; i>0; i--)
	printf("%d ",Items[i]);
	
	getchar();
	getchar();
	return 0;
}


and here is the result

Photo Result

EDIT: I don't know why the photo of the results is not showing but it's something like

Code:
Introduce 20 numbers followed by return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
-858993460 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5  4 3 2


debugged in cmd

Reply With Quote
  #2  
Old December 12th, 2012, 03:39 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,907 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 39 m 56 sec
Reputation Power: 1774
> for (i=20; i>0; i--)
This should be
for (i=19; i>=0; i--)
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 12th, 2012, 08:32 PM
Bloodyred Bloodyred is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 Bloodyred User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by salem
> for (i=20; i>0; i--)
This should be
for (i=19; i>=0; i--)

Thanks so much, that work perfectly!
Now if it is not too much to ask i would to know, the reason why is that serie of number showing and why is diferent
Code:
(i=19; i>=0; i--)
from
Code:
(i=20; i>0; i--)

Reply With Quote
  #4  
Old December 13th, 2012, 12:47 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,907 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 39 m 56 sec
Reputation Power: 1774
Rather than printing Items[i], why not just print i instead.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > -858993460 Value when use prinft, please help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap