473,378 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how do I print a reverse order of these numbers in this while loop

Hello how do I print a reverse order of these numbers in this while loop. I'm using array.

Expand|Select|Wrap|Line Numbers
  1.   Sub Main()
  2.         Dim data() = {30, 32, 81, 43, 58, 85, 23, 19}
  3.         Dim i = 0
  4.  
  5.         While (i > 8)
  6.  
  7.             Console.WriteLine(data(i))
  8.             i = i + 1
  9.  
  10.         End While
  11.     End Sub
Oct 29 '19 #1
3 3975
gits
5,390 Expert Mod 4TB
well - if you have to use the while loop then 1st you would need to make sure it runs at all - the condition in line 5 is never met - so fix the comparison. now - i is counting up and so you just would need to access the elements from the end in that kind of loop - which basically means that you could use something like (Pseudocode here):

Expand|Select|Wrap|Line Numbers
  1. indexOfElementInTheLoop = (data.Length - 1) - i
a much cleaner way here would probably be a For-loop though - where you count down from the array's length-1 to 0 and you may use the counter directly to access the elements.
Oct 30 '19 #2
cactusdata
214 Expert 128KB
Use a For-Next loop:

Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.  
  3.     Dim data() As Integer = {30, 32, 81, 43, 58, 85, 23, 19}
  4.     Dim index As Integer
  5.  
  6.     For index = data.Length - 1 To 0 Step -1    
  7.         Console.WriteLine(data(index).ToString())
  8.     Next
  9.  
  10. End Sub
Oct 30 '19 #3
Sherin
77 64KB
Try This Code

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main() {
  3.     int n, rev = 0, remainder;
  4.     printf("Enter an integer: ");
  5.     scanf("%d", &n);
  6.     while (n != 0) {
  7.         remainder = n % 10;
  8.         rev = rev * 10 + remainder;
  9.         n /= 10;
  10.     }
  11.     printf("Reversed number = %d", rev);
  12.     return 0;
  13. }
Output

Expand|Select|Wrap|Line Numbers
  1. Enter an integer: 1234
  2. Reversed number = 4321
Apr 10 '20 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James Lee | last post by:
I am doing a simple query like col1, col2, date, col4 from table1. All four colums are of type blob. For date column, I store a string like this: Fri Feb 13 11:01:24 2004 I store records as...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
8
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;
15
by: Fabio Cannizzo | last post by:
Is it possible to do something similar to the STL iterators, i.e. to execute a foreach loop in reverse order? Thanks, Fabio
10
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...
6
by: raghuveer | last post by:
i want to print my linked list in the reverse order ie..last item first and first item last..this is what i have so far struct linked_list { int number; struct linked_list *next; }; typedef...
5
by: dav3 | last post by:
I have almost completed a monster assignment on sorting algorithms (quick, insertion and selection) using c++ but I am lost on one part of the assignment. I have to generate a random list of numbers...
6
by: bitong | last post by:
The problem is input a number then the output should be in reverse order.. I already made a code but only good for 9 - digit only...What I want to do is to hold infinite digit, in other words don't...
1
by: Charles Smith | last post by:
Using vba in access to print multi page reports. I would like to have them print in reverse order.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.