Sep 25, 2017 at 5:29am UTC
Hey Guys!
I have this for loop with this following data
79927398713
and it isn't working
1 2 3
for (i = size -1 ; i <=0; i = i - 2)
{
}
i have to ignore the last digit(3) and i need to start the for loop counting right to left
Does anyone have an idea why is not working ?
Thanks
Last edited on Sep 25, 2017 at 5:29am UTC
Sep 25, 2017 at 9:23am UTC
What i am trying to ask is that i have an array with this data 79927398713, what i need to do is ignore the last digit(3) for future operations, and start looping from right to left
so 1, 7, 8 and so on.
if i do as im trying it doesn't work.
Sep 25, 2017 at 9:33am UTC
Your original post was far from clear.
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
using namespace std;
int main()
{
string data = "79927398713" ;
for ( int i = data.size() - 2; i >= 0; i-- ) cout << data[i] << " " ;
cout << endl;
}
If you want your data as a (long) int then
1 2 3 4 5 6 7 8 9 10
#include <iostream>
using namespace std;
int main()
{
unsigned long long idata = 79927398713;
unsigned long long temp = idata;
while ( ( temp /= 10 ) > 0 ) cout << temp % 10 << " " ;
cout << endl;
}
Last edited on Sep 25, 2017 at 9:47am UTC