its here why isit like that -
#include <stdio.h>
-
int z[10];
-
int y;
-
void reverse_order(int x[],int y)
-
{
-
for (y = 9; y >=0; --y)
-
{
-
printf("%d \t",x[y]);
-
}
-
}
-
int main(void) {
-
-
printf("Enter any numbers of your choice \n");
-
for (y = 0; y <10; ++y)
-
{
-
scanf("%d\t", &z[y]);
-
-
}
-
printf("the reverse of the entered numbers is\n");
-
reverse_order(z,y);
-
return 0;
-
}
8 1633
its here why isit like that -
#include <stdio.h>
-
int z[10];
-
int y;
-
void reverse_order(int x[],int y)
-
{
-
for (y = 9; y >=0; --y)
-
{
-
printf("%d \t",x[y]);
-
}
-
}
-
int main(void) {
-
-
printf("Enter any numbers of your choice \n");
-
for (y = 0; y <10; ++y)
-
{
-
scanf("%d\t", &z[y]);
-
-
}
-
printf("the reverse of the entered numbers is\n");
-
reverse_order(z,y);
-
return 0;
-
}
You are using two different size loops. In you enter you are using 10 for a loop which goes 0,1,2,3,4,5,6,7 ,8,9 or 10 entries in your reverse loop you are 9 which goes 0,1,2,3,4,5,6,7 ,8 or 9 entries. Change you reverse loop to 10 and it will work as you expect.
Jim
JosAH 11,448
Recognized Expert MVP
I'd say get rid of that '\t' in the scanf format specifier.
kind regards,
Jos
Banfa 9,065
Recognized Expert Moderator Expert
You are using two different size loops. In you enter you are using 10 for a loop which goes 0,1,2,3,4,5,6,7 ,8,9 or 10 entries in your reverse loop you are 9 which goes 0,1,2,3,4,5,6,7 ,8 or 9 entries. Change you reverse loop to 10 and it will work as you expect.
You statement about the reverse for loop is not true.
it starts at 9 and iterates while y >= 0 for values 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 inside the loop.
You statement about the reverse for loop is not true.
it starts at 9 and iterates while y >= 0 for values 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 inside the loop.
You are correct, I should have said 11 for the input and 10 for the output. The result is the same, the arrays are not of equal length.
Jim
JosAH 11,448
Recognized Expert MVP
You are correct, I should have said 11 for the input and 10 for the output. The result is the same, the arrays are not of equal length.
Jim
That isn't true either; for (int y= 0; y < 10; ++y) loops ten times, not eleven times.
kind regards,
Jos
RRick 463
Recognized Expert Contributor
From the original code, - Why are you passing y to the subroutine, when you overwrite its value in the for loop?
- If y is the size of the array (i.e y=10) then the - -y decrement will work
- If y is the index to the last entry (i.e. y=9), then change - -y to y- -
Ganon11 3,652
Recognized Expert Specialist - If y is the size of the array (i.e y=10) then the - -y decrement will work
- If y is the index to the last entry (i.e. y=9), then change - -y to y- -
Shouldn't both work, since the last statement in the for loop header is only executed at the end of the loop?
RRick 463
Recognized Expert Contributor
You're right. The decrement order doesn't matter. It's the middle conditional that gets checked after the intialization and each loop.
Sooo, we are back to the loops. Both loops are using a different countint base, but end up with the same number of entries.
When you remove the '\t' from the printf, does your program work correctly??
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Shufen |
last post by:
Hi,
I'm a newbie that just started to learn python, html and etc. I have
some questions to ask and hope that someone can help me on.
I'm trying to code a python script (with HTML) to get values from a
html form that consists of about 10 checkbox and a textbox where user
have to key in a value to perform a search.
From python tutors, I learned that I have to use the following method:
|
by: Lucas Raab |
last post by:
I am currently in the process of porting some C code into Python and am
stuck. I don't claim to be the greatest C/C++ programmer; in fact, my
skills at C are rudimentary at best. My question is I have the
statement: "typedef unsigned long int word32" and later on: "word32
b" referencing the third bit of the integer. How do I do the same in
Python?? If this is a stupid, I apologize. It's amazing what the lack of
sleep does to the brain....
|
by: vijay |
last post by:
Hello,
As the subject suggests, I need to print the string in the reverse
order. I made the following program:
# include<stdio.h>
struct llnode
{
char *info;
|
by: Martin Jørgensen |
last post by:
Hi,
I don't understand these errors I get:
g++ Persort.cpp
Persort.cpp: In function 'int main()':
Persort.cpp:43: error: name lookup of 'j' changed for new ISO 'for' scoping
Persort.cpp:37: error: using obsolete binding at 'j'
|
by: aatish19 |
last post by:
1: Write a program that asks the user to input an integer value and
print it in a reverse order
Sample Output
Enter any number 65564
Reverse of 65564 is 46556
2: Write a program that takes a string as an input and print it in
reverse order.(don't use bulit-in/library function).
Sample Output
Enter any string: i m Kashif
| |
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project where someone
suggested to me I was spending too much time writing error messages,
and that I was therefore missing the benefit of using a scripting
language. The idea, apparently, is that the PHP interpreter writes all
the error messages that are...
|
by: Kosmos |
last post by:
Hey guys...as a relatively new programmer, I try to give back where I can. Below is the code for a useful program I believe many of you could use...just don't use the same exact code because...well I don't work for myself if you get my drift....anyways even if this is not asked of you...it might get you on friendly terms with the lawyers in the office
The code is written to extract information from a table with contract information and divide...
|
by: Hazza |
last post by:
Hi, I am using PHP and mysql to create a website.
I am fairly new to PHP, and thus am grateful to anyone who helps!
Firstly I am running a homepage, that displays additional content if a user has logged in. I set a loggedin session in the log in page, which I have tested and works fine in other scripts.
I am displaying news on the homepage (which is stored in a mysql database), and this works fine when the user accesses the homepage...
|
by: jamitwidme |
last post by:
Hello everyone
Can someone help me fix this problem?
I am using an example from Pyro(Python Remote Object) website
directly.
It is the last example from
http://pyro.sourceforge.net/manual/8-example.htm
I have two computers to run Server and Client.
############################################
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |