#include<iostream>
using namespace std;
void main()
{
int pro[100];
for(int a=100;a>=1;a--)
{
pro[a]=a;
cout<<pro[a]<<"\t";}
}
coolboss
0
Newbie Poster
Recommended Answers
Jump to PostIf you write a loop that runs backward through an array, it is a good idea to get into the habit of decrementing the control variable at the beginning of the loop:
…int pro[100]; for (int a = 100; a > 0;) { --a; // whatever }
Jump to PostBy the way, let me elaborate on what I mean about iterators. Consider iterating backward through a list<int>. You can't write
// This code does not work! for (list<int>::iterator it = mylist.end()-1; it >= mylist.begin(); --it) { // stuff }
for two reasons: (1) List iterators don't …
All 7 Replies
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
arkoenig
340
Practically a Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
arkoenig
340
Practically a Master Poster
arkoenig
340
Practically a Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
arkoenig
340
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.