0

How do i print values of an array using macros in C

I've an array arr[] ={1,2,3,4,5,6,7,8,9} And I've to display arr[5],arr[2],arr[1],arr[3] Using just single printf statement and single format specifier %d so how do i do so There's no limitation for loops and using other format specifiers Here's the code I'm trying to do https://code.sololearn.com/cBA8W8IN75DN/?ref=app

7th Dec 2018, 5:18 PM
Madhusudan Babar
Madhusudan Babar - avatar
3 ответов
+ 3
I'd use this for my printing: printf("arr[%i] = %d\n",k,arr[k]); If %i shouldn't be used, change to %c and change first k to k+48 (only works for k <= 9).
7th Dec 2018, 6:26 PM
John Wells
John Wells - avatar
+ 3
He was restricted to one %d in original question, Baptiste E. Prunier.
8th Dec 2018, 2:05 PM
John Wells
John Wells - avatar
0
John Wells why using %i or %c ? Why not %d or %1d ?
8th Dec 2018, 7:14 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar