how to printf only number in odd index/array? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 1

how to printf only number in odd index/array?

example: input 1 2 3 4 5 //a[0] a[1] a[2] a[3] a[4] output 2 4 // because 2 is in index a[1] and 4 is in index a[3] which is odd number

23rd Oct 2018, 3:27 PM
Yoaraci
Yoaraci - avatar
1 Réponse
+ 1
for(i=1;i<arsize;i+=2) cout<<ar[i]; OR for(i=0;i<arsize;++i) if(i%2) cout<<ar[i];
23rd Oct 2018, 4:33 PM
Megatron
Megatron - avatar