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 1630
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...
|
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...
|
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:...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |