Beginner at c

Joined
Oct 5, 2023
Messages
1
Reaction score
0
I just started coding, I wrote this code, it's exercise in book "C programing language", sorry that the code variables are not written in english, it seems that if number of words gets past 9, * and numbers below dont lineup, how can i fix that, and if you see better solution for code tell me,
Thanks.

#include <stdio.h>
#include <limits.h>
int main()
{
int c;
int flag=1;
int i;
int reci[100];

for(i=0; i<101; i++){
reci=0;
}
i=0;
while((c=getchar())!=EOF){
if(c==' ' || c=='\t' || c=='\n'){
i++;
flag=0;
}else flag=1;
if(flag==1){
reci++;
}
}
int maks=INT_MIN;
for(i=0; i<101; i++){
if(reci>maks){
maks=reci;
}
}
int j;
int linija=maks+1;
for(i=maks; i>=1; i--){
printf("%3d |", linija-=1);
for(j=0; j<101; j++){
if(reci[j]>=i){
printf(" *");
}else printf(" ");
}
printf("\n");
}
printf(" ");
for(i=0; i<101; i++){
if(reci>0){
printf("---");
}
}
printf("\n\t ");
for(i=0; i<101; i++){
if(reci>0){
printf("%d ", i+1);
}
}

return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,828
Messages
2,569,736
Members
45,518
Latest member
vlonesshirt

Latest Threads

Top