C Programming Tutorial – 29 – break

40
139



Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –

Nguồn:https://quydinh.com/

Xem Thêm Bài Viết Khác:https://quydinh.com/cong-nghe

40 COMMENTS

  1. same program without break
    #include <stdio.h>

    #include <conio.h>'

    #include <ctype.h>

    #include <string.h>

    #include <math.h>

    int main()

    {

    int times;

    int a;

    printf("how many times do you want to loop:");

    scanf("%d",&times);

    for(a=1;a<=times; a++){

    printf("%dn",a);

    }

    return 0;

    }

  2. this is easiest way but not included break
    int a;
    int howmany;
    printf("How many times do you want?");
    scanf("%d", &howmany);

    for(a=1; a<=howmany;a++){
    printf("%d n",a);
    }

  3. I am really glad you made these awesome videos and all but geez you sure say 'pretty much' a lot which is a bit annoying and redundant. I hope you learned how to quit doing that by now.

  4. can i also do this?

    int main ()
    {

    int a;
    int z;

    printf("your number: ");
    scanf("%d",&z);

    for (a=1;a<=z;a++)
    {
    printf("%d",a);
    }

    return 0;
    }

  5. int a;
    int howmany;
    int max;

    printf("HOW MANY TIMES LOOPS ?n");
    scanf( "%d", &howmany);

    printf("What is maximum number ?n");
    scanf( "%d", &max);

    for (a = 1; a <= max; a++){
    printf( "%dn",a);

    if (a==max){
    break;
    }
    }

  6. so if i want an error check, maybe like if they put something greater than 10, can i make an if statement saying
    if (howmany>10) {printf("please input number between 0 and 1");}

  7. Why can't I initialize a variable inside of the forloop like > for(int i = 0; i < 5; i++) {} …. It was possible in CS50 ide so I am quite confused atm, does it depend on the ide or what?

  8. #include <stdio.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <math.h>

    int main()
    {

    int a;
    int howMany;
    int maxamount = 10;

    printf("how many times as you want loop to loop? (up to 10) ");
    scanf(" &d", &howMany);

    for(a=1; a<=maxamount; a++){
    printf("%dn", a);

    if(a==howMany){
    break;

    }

    }

    return 0;

    }

    it dosent wooooork!! help please

  9. So we can Also use Letters instead of Number
    i had Made one and it Works

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
    char a;
    char howMany;
    char maxAmount = 'z';

    printf("How many times you wanted this loop to loop? ");
    scanf(" %c",&howMany);

    for (a='a';a<=maxAmount;a++){
    printf("%cn",a);

    if(a==howmany){
    break;
    }
    }

    return 0;
    }

  10. so you can also do
    for(a = 1;a <= howMany ; a++){

    printf("Loop: %d", a);
    if(a == maxAmount){
    break;
    }
    …………….. now im just confusing myself.

  11. Why doesnt it work ?

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <math.h>

    int main()
    {
    int a;
    int b;

    printf("Press p many times!!!n");

    while(b>100) {
    scanf("%s",a);

    if(a=='p') {
    b++;
    } else{
    printf("Youve lost the game.");
    break;
    }
    }

    return 0;
    }

  12. bro i wanted to create a program which calculates points from every questio.like the question have options: a,b,c,d and each option have different points,and at the end of the process,it totals out and prints the outcome according to diffrernt points….i am really confused on this….can you give me some tips??

  13. Have fun with this little piece of code guys:

    #include "stdio.h"
    #include "stdlib.h"
    #include "ctype.h"
    #include "string.h"
    #include "math.h"

    int main()
    {

    int number, guess, i;

    number = 21;
    i = 0;

    printf("%sn", "Hello, I'm thinking of a number, you're gonna guess it in three tries!");

    while(i++ < 3)
    {

    printf("%s %d: ", "Try number", i);
    scanf("%d", &guess);

    if (guess > number)
    {
    printf("%sn", "It's lower than that! Try again!");
    } else if (guess < number)
    {
    printf("%sn", "It's higher than that! Try again!");
    } else {
    printf("%s %d %s!n", "Great job! You guessed it in ", i, (i == 1) ? "try" : "tries");
    break;
    }
    }

    printf("%sn", "Oops! Game over!");

    return 0;

    }

  14. For some reason, my code doesn't work. I'm pretty sure it's correct: 
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <math.h>

    int main()
    {
        int a;
        int howMany;
        int maxAmount = 10;

        printf("How many rows do you want to print? (up to 10) ");
        scanf(" %d", &howMany);

        for(a=1; a<=howMany; a++){
            printf("%dn", a);
            if(a==maxAmount){
                break;
            }
        }

        return 0;
    }

  15. It doesn't break if I enter 10+ value. :/

    Here is code I written:

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <math.h>

    int main()
    {
       int number;
       int howMany;
       int maxAmount = 10;

       printf("How many times you want loop to loop? (Up to 10) n");
       scanf(" %d", &howMany);

       for(number=1; maxAmount<=10; number++){
            printf("%dn", number);

        if(number==howMany){
            break;
        }
       }
       return 0;
    }

    What's Wrong? :/

  16. Im confused… I input this code and it did not break (aside from that my code wouldnt even run if didn't take off maxAmount and manually input 10). Can someone please tell me what I did wrong?

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <ctype.h>
    #include <string.h>

    int main()
    {

        int a;
        int howMany;
        
        printf("How many times do you want this program to loop?(up to 10 times) ");
        scanf(" %d", howMany);
        
        for(a=1; a <= 10 ; a++){
            
            printf("%dn", a);
            
            if(a==howMany){
                break;
            }
        }
        return 0;
    }

  17. Thank you much, these tutorials are extremely helpful.
    Question: what would I do if I absolutely wanted the user to type a number under 10? Could I include another IF statement under FOR loop specifying that:

    if (howmany > 10)
    {
    printf ("Invalid entry. Please enter a value less than 10.n");
    }

    Is this correct?

  18. Why don't we just use this way ? : 
    int main()
    {
      int a,i;
      printf("How many loops?: ");
      scanf("%d",&a);
      for(i=0;i<=a;i++){
        printf("%d",i);
      }
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here