Help me with this exercise in C

I can't a logic for this exercise!


make a program that count (00) 16 to (FF) 16. The result on the screen should be as follows: 00 01 02 03 04 05 06 07 08 09 0b 0a 0c 0d 0e 0f 10 11 12. . . f7 f8 f9 fa fb fc fd fe ff.
Tips: Use loops that use direct char variables, ranging digit by digit.

This exercise is the 10 of link:

http://www.decom.ufop.br/guillermo/BCC201/Listas/Lista1-BCC201-Prova1.pdf

My code:

#include <stdlib.h>
#include <stdio.h>

int main()
{
int i, j;
char k;


for(i = 0; i <= 16; i++){
for(j = 0; j <= 9; j++){
printf("%d%d ", i, j);
}
for(k = 'a'; k <= 'f'; k++){
printf("%d%c ", i, k);
}
}
printf("\n\n");
system("pause");
return 0;
}


when you can't reason it out in your head write it on paper.
Your on the right track with 2 loops.

// make char for large tens and ones
1
2
char T;
char O;


// loop tens 0-15

if (tens ==10){T='a';}
// continue 11-15

// loop ones 0-15

if (ones ==10){O='a';}
// continue 11-15

// use if statement to choose what to print

1
2
3
4
5
6
7
8
	if ( tens >= 10)
		{cout << T;}
	else 
		{cout << tens;}
	if (ones >= 10)
		{cout << O << " ";}
	else 
		{cout << ones << " ";}


// After the ones loop, add a newline.
Last edited on
Topic archived. No new replies allowed.