Video není dostupné.
Omlouváme se.

C nested loops ➰

Sdílet
Vložit
  • čas přidán 14. 08. 2024
  • C nested loops tutorial example explained
    #C #nested #loops

Komentáře • 47

  • @BroCodez
    @BroCodez  Před 2 lety +35

    #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 Před 2 lety +2

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

    • @nem0103
      @nem0103 Před 2 lety +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 Před 9 měsíci

      @@nem0103 thanks had same issue

    • @naimulhasannahid994
      @naimulhasannahid994 Před 8 měsíci

      thx@@nem0103

  • @axiking6894
    @axiking6894 Před rokem +38

    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 Před 6 měsíci +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 Před rokem +10

    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

  • @Leshotgun
    @Leshotgun Před 2 lety +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 Před 2 lety +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.

  • @frankezic4245
    @frankezic4245 Před 2 lety +2

    thanks, Bro (Code)

  • @lilsolace118
    @lilsolace118 Před 6 dny

    can you more than 2 nested loops and how does that work?

  • @dillikalaunda4632
    @dillikalaunda4632 Před 2 lety +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?

  • @jezrielmaydelossantosilawa6647

    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 Před 6 měsíci

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

  • @elsayedelsaghir8723
    @elsayedelsaghir8723 Před rokem

    thank you bro

  • @PSIwolf39
    @PSIwolf39 Před 8 měsíci +1

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

  • @user-zh2xu2qd2i
    @user-zh2xu2qd2i Před 11 měsíci

    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?

  • @bison9499
    @bison9499 Před rokem

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

  • @giahuybui8323
    @giahuybui8323 Před rokem +1

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

    • @zuki2018
      @zuki2018 Před rokem +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 Před 11 měsíci

      Hey thanks man , that worked

  • @boweryst11
    @boweryst11 Před rokem +1

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

  • @cholobikomochi5952
    @cholobikomochi5952 Před rokem +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 Před rokem +6

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

      for(int i=1; i

  • @spicasuzuki1908
    @spicasuzuki1908 Před 2 lety +5

    code... where?

  • @ryanalnaser914
    @ryanalnaser914 Před 2 lety +1

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

  • @samantharazon8009
    @samantharazon8009 Před 2 lety

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

  • @deathmeter7243
    @deathmeter7243 Před 2 lety +2

    75 views…

  • @multicitygirl5527
    @multicitygirl5527 Před 2 lety

    thank uuuuuuuu

  • @ibrahimhakem5953
    @ibrahimhakem5953 Před 2 lety

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