C nested loops ➰

Поділитися
Вставка
  • Опубліковано 7 лис 2024

КОМЕНТАРІ • 50

  • @BroCodez
    @BroCodez  3 роки тому +47

    #include
    int main()
    {
    //nested loop = a loop inside of another loop
    int rows;
    int columns;
    char symbol;
    printf("
    Enter # of rows: ");
    scanf("%d", &rows);
    printf("Enter # of columns: ");
    scanf("%d", &columns);
    scanf("%c"); //clears
    from buffer
    printf("Enter a symbol to use: ");
    scanf("%c", &symbol);
    for(int i = 1; i

    • @nem0103
      @nem0103 2 роки тому +2

      i tried to run this but any number i input it always show 10 columns, why is that?

    • @nem0103
      @nem0103 2 роки тому +12

      nvm i fixed it, it works on devc++ compiler but in online compiler and vscode it didn't
      so i just add &symbol at the end scanf("%c", &symbol); like this
      instead of just scanf("%c");

    • @damienvalderrama
      @damienvalderrama Рік тому

      @@nem0103 thanks had same issue

    • @naimulhasannahid994
      @naimulhasannahid994 11 місяців тому

      thx@@nem0103

  • @axiking6894
    @axiking6894 Рік тому +48

    if the scanf("%c"); don't work for some peoples, replace it by getchar(); at the same place he put the scanf("%c");

  • @zhyakoxalid6892
    @zhyakoxalid6892 9 місяців тому +1

    Thank you very much, I was looking for something to explain the nested loop and how they interact which you explained in 3:14, "in order for one iteration of the inner loop to run, the inner loop basically has to end, to stop"

  • @masterschlib
    @masterschlib Рік тому +13

    you could also scan past the
    character from scanf by putting a space before “%c”
    like “ %c”
    correct me if i’m wrong tho lol

    • @nourguilal
      @nourguilal Рік тому

      thnx G IT WORKS

    • @ahmetyusufata2710
      @ahmetyusufata2710 17 днів тому

      at here right?: printf("Enter a symbol to use: ");
      scanf(" %c", &symbol);

    • @masterschlib
      @masterschlib 17 днів тому

      @@ahmetyusufata2710yeah i think that’s right

  • @frankezic4245
    @frankezic4245 2 роки тому +3

    thanks, Bro (Code)

  • @jezrielmaydelossantosilawa6647
    @jezrielmaydelossantosilawa6647 2 роки тому +3

    my problem is I need to do a 5 10 15 20 up to 500 but it should be at 11 rows. how do I do that.

    • @prosaufi3692
      @prosaufi3692 9 місяців тому

      First loop i is 11 times . Then 2nd loop just incremeent j += 5

  • @dillikalaunda4632
    @dillikalaunda4632 2 роки тому +2

    hey! i love your channel! i tried to replicate this code and for some reason, it prints the character twice the number i put in columns, i fixed it by making the initial value of j = 6, but i dont think thats supposed to happen, cause it doesnt make any sense. please help?

  • @Leshotgun
    @Leshotgun 2 роки тому +3

    vsc gets hung up on the fact that the additional scanf statment(the one added to clear the
    ) and it wont compute correctly

    • @oscare123
      @oscare123 2 роки тому +6

      You could also write getchar(); to consume the /n
      or you could add a space before %c like this scanf(" %c", &symbol); to tell it to ignore whitespace characters such as /n.

  • @OnkabetseMogomotsi-k1d
    @OnkabetseMogomotsi-k1d Рік тому

    My end results prints to infinite it never stops unless I kill the terminal and I did exactly like you did. What could I have done wrong?

  • @PSIwolf39
    @PSIwolf39 11 місяців тому +1

    Here's a nested loop I made:
    #include
    #include
    #include
    #include
    #include
    int main(){
    for(int i = 0; i

    • @ZuKosElorian
      @ZuKosElorian 11 місяців тому

      what is this abomination

  • @elsayedelsaghir8723
    @elsayedelsaghir8723 Рік тому

    thank you bro

  • @giahuybui8323
    @giahuybui8323 Рік тому +1

    why my output is 10 columns even though I type another number when enter the columns
    ?

    • @zuki2018
      @zuki2018 Рік тому +1

      Are you on a Mac? I have the same issue, using getchar(); instead of scanf("%c"); solves the problem, as suggested in comments below.

    • @dkp8230
      @dkp8230 Рік тому

      Hey thanks man , that worked

  • @Vegeta6777
    @Vegeta6777 Рік тому

    It recognises the enter rows, columns, and symbol but after that nothing prints ??

  • @boweryst11
    @boweryst11 Рік тому +1

    tried anything but it just keeps saying more% conversions than data arguments

  • @cholobikomochi5952
    @cholobikomochi5952 2 роки тому +1

    Create a Program applying NESTED LOOP that will display the output 123 345 567. please help me i can not do it

    • @houbini6097
      @houbini6097 2 роки тому +6

      If you still need it. This should work.
      #include
      int main(void)
      {
      int j = 2;
      int count;

      for(int i=1; i

  • @samantharazon8009
    @samantharazon8009 2 роки тому

    Hi there, love ur channel! please post the code? Thanks!

  • @SpicaSuzuki
    @SpicaSuzuki 3 роки тому +5

    code... where?

  • @ryanalnaser914
    @ryanalnaser914 2 роки тому +1

    whatever anything before or after or anything or I do or did or anything or anytime

  • @deathmeter7243
    @deathmeter7243 3 роки тому +3

    75 views…

  • @multicitygirl5527
    @multicitygirl5527 3 роки тому

    thank uuuuuuuu

  • @ibrahimhakem5953
    @ibrahimhakem5953 2 роки тому

    it's the alone video than i want to have the code, and... nothing