-2

I'm trying to get my program to repeat the letter "a" 255 times, but for some reason this prints "a" just once and then stops.

#include <stdio.h>
int main(){
    for(int e = 0; e < 253; e++);
    {
        printf("a");
    }
    printf("\n");
    return 0;
}
Wasi Ahmad
  • 31,685
  • 30
  • 101
  • 155
kouta-kun
  • 1
  • 2

2 Answers2

2

This is how you should do it.

#include <stdio.h>
int main(){
    for(int e = 0; e < 253; e++)
    {
            printf("a");
    }
    printf("\n");
    return 0;
}
Vimbuddy
  • 156
  • 6
  • 18
2

There is a semicolon end of this loop for(int e = 0; e < 253; e++);. The for loop just runs without doing anything. Finally the rest of the statement gets executed and you get only one print.

haasi84
  • 104
  • 3