Home > Back-end >  How do I format a table like shown in C
How do I format a table like shown in C

Time:10-16

I have to print numbers like so

table

The assignment "The rst number is printed right-justified in 5 spaces then a colon is printed then then number of steps is written as a left justified number in 5 spaces"

The code I have now prints numbers like so

    3:7    4:2    5:5    6:8    7:16    8:3    9:19   10:6
   11:14   12:9   13:9   14:17   15:17   16:4   17:12
   18:20   19:20   20:7

This is the code to print that table.

void makeTable(int start, int end) {
  for(int i = 0; i<=end-start; i  ) {
    printf("]:%d", i start, hofpo(i start));
    if(i>0 && i % 7 == 0) {
      printf("\n");
    }
  }
  printf("\n");
}

How do I print the numbers in the format that is needed?

CodePudding user response:

I summed up the comments for the newcommers:

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

void makeTable (int, int);

int main (int argc, char * *argv, char * *envp) {
    makeTable(5, 35);
    return (EXIT_SUCCESS);
}

void makeTable(int start, int end) {
    for(int i = 0; i<=end-start; i  ) {
        printf("-:%-3d", i start, i start-3);
        if(i>0 && (i 1) % 7 == 0) {
            printf("\n");
        }
    }
    printf("\n");
}
  • Related