Help with a Astrix bar chart

limited knowledge of C programming, however I’m attempting to have the user input 5 integers and have them be displayed as a vertical bar chart with the corresponding 1-10 digits being represented on a table 5x10 in ‘*’.

if you guys run the program you will realise the problem has the formulas on the right of my coding (although very muddled up and tried and tested) always seems to be a matter of … I can’t do it!
i THINK i need multiple different formulas on each line that have to work for all values of x (1-10).
for the last line of bunch of coding at eh bottom (the first line in my bar chart) I tried things such as 10*(num1/num1) so the total was always 42= * .

#include <stdio.h>

int main()
sixfive = ‘A’;
char space;
space = 32;
int num1, num2, num3, num4, num5;

printf(“enter 5 digits\n”);
scanf("%d %d %d %d %d", &num1,&num2,&num3,&num4,&num5);

printf("%c", space+(10*((num1*num1)/100)));
   printf("   %c", space+(10*(num2*num2/100)));
      printf("   %c", space+(10*(num3*num3/100)));
         printf("   %c", space+(10*(num4*num4/100)));
            printf("   %c\n", space+(10*(num5*num5/100)));

         printf("%c", space+(10*(num1*num1/81)));
            printf("   %c", space+(10*(num2*num2/81)));
      printf("   %c", space+(10*(num3*num3/81)));
         printf("   %c", space+(10*(num4*num4/81)));
            printf("   %c\n", space+(10*(num5*num5/81)));

            printf("%c", space+(10*(num1*num1/64)));
            printf("   %c", space+(10*(num2*num2/64)));
      printf("   %c", space+(10*(num3*num3/64)));
         printf("   %c", space+(10*(num4*num4/64)));
            printf("   %c\n", space+(10*(num5*num5/64)));

 printf("%c", space+(10*(num1*num1/49)));
   printf("   %c", space+(10*(num2*num2/49)));
      printf("   %c", space+(10*(num3*num3/49)));
         printf("   %c", space+(10*(num4*num4/49)));
            printf("   %c\n", space+(10*(num5*num5/49)));

            printf("%c", space+(10*(num1*num1/36)));

printf(" %c", space+(10*(num2num2/36)));
printf(" %c", space+(10
printf(" %c", space+(10
printf(" %c\n", space+(10

            printf("%c", space+(10*(num1*num1/25)));
   printf("   %c", space+(10*(num2*num2/25)));
      printf("   %c", space+(10*(num3*num3/25)));
         printf("   %c", space+(10*(num4*num4/25)));
            printf("   %c\n", space+(10*(num5*num5/25)));

            printf("%c", space+(10*(num1*num1/16)));
   printf("   %c", space+(10*(num2*num2/16)));
      printf("   %c", space+(10*(num3*num3/16)));
         printf("   %c", space+(10*(num4*num4/16)));
            printf("   %c\n", space+(10*(num5*num5/16)));

            printf("%c", space+(10*(num1/4)));
   printf("   %c", space+(10*(num2/4)));
      printf("   %c", space+(10*(num3/4)));
         printf("   %c", space+(10*(num4/4)));
            printf("   %c\n", space+(10*(num5/4)));

            printf("%c", space+(10*(num1/3)));
   printf("   %c", space+(10*(num2/3)));
      printf("   %c", space+(10*(num3/3)));
         printf("   %c", space+(10*(num4/3)));
            printf("   %c\n", space+(10*(num5/3)));

            printf("%c", space+(10*(num1/2)));
   printf("   %c", space+(10*(num2/2)));
      printf("   %c", space+(10*(num3/2)));
         printf("   %c", space+(10*(num4/2)));
            printf("   %c\n", space+(10*(num5/2)));

            printf("%c", space+(10*(num1/num1)));
   printf("   %c", space+(10*(num2/num2)));
      printf("   %c", space+(10*(num3/num3)));
         printf("   %c", space+(10*(num4/num4)));
            printf("   %c\n", space+(10*(num5/num5)));

printf(“1 2 3 4 5\n”);
return 0;


okay, we have very different idea’s on how we should build such a program, here is my version:

#include <stdio.h>

int main()
int array[5];
int number=0;
int high = 0;

for(int i = 0; i < 5; i++){
   printf("entrer number %i:\n", i + 1);
   scanf("%i", &number);
   array[i] = number;
for(int i = 0; i < 5; i++){
   if (array[i] > high){
      high = array[i];
for (high; high > 0; high--){
   for (int i = 0; i < 5; i++){
      if (array[i] >= high){
         printf(" * ");
      else {
         printf("   ");
   high = high--;
for (int i = 0; i < 5; i++){
   printf(" %i ", array[i]);
   /* if you just want to pritn 1 till 5, uncomment the line below */
   //printf(" %i " i);

as you can see, i build my own version. Now, this version is very different from yours, and no idea if it is even close to what you want

1 Like

hello. thank you for your reply, however the challenge is to use only the operations i have used on my code. using maths and ascii to build the table.

but thank you

too be honest, i find that a super overcomplication

yes but thats the challenge :frowning:

what can i use? and what can i not use?

everything that you see there is generally the format of what i want, however you can change up the formulas on the right of each line to make it work for all values of x and above.
for example line 6 needs to equal 42 when you put in 6
but also equal 42 when you put in 7 or 8 or 9 or 10 for example.
I’m sure you understand

I am sorry, but i am not going to do this, it is sooooo overcomplicated, good luck!

I found my solution to be easier and working perfectly, i know it is not for your challenge, but you try and run it?

your way also shows the total matrix at the bottom axis where min labels the numbers 1-5

i wasn’t sure what do with that, the file contains a comment at the end, which will print 1 till 5 if uncomment, do comment out the line above it then, otherwise it will print both