How to print reverse for loop from right to left below is my for loop which displays value like this I want to change output like mirror image value that show from left to right I want to show from right to left see below:
int r;
int p;
r=31;
for (i = 0,p=r; i < week_no; i++,p--)
{
HoyahCalendar.a[i / 7][i % 7] = String.valueOf(p);
}
Output is like this
31 30 29 28
I want to show like
28 29 30 31
One solution is to change
for (i = 0,p=r; i < week_no; i++,p--)
To
for (i = 0,p=r-week_no; i < week_no; i++,p++)
You can initialize p to 28 and increment it with each iteration of the loop as follows:
int r;
int p;
r=28;
for (i = 0,p=r; i < week_no; i++,p++)
{
HoyahCalendar.a[i / 7][i % 7] = String.valueOf(p);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.