Print 1 to N numbers using GOTO-STATEMENT in C

Solution: In this tutorial, we will discuss how to print 1 to N numbers using in GOTO-STATEMENT C. Using label, we can print up to n numbers which is given by the user. Here we will see how to perform GOTO-STATEMENT to print 1 to N numbers in C. This program is very easy for everyone.So let’s start it.

Hints:

  • Declare only two variables.
  • One variable is used for taking input and other to print upto input number
  • First take an integer number input from the user.
  • Perform GOTO-STATEMENT.

CODE:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{

    int n,i=1;  // VARIABLES DECLARATION
    printf("\t----------------------------------------\n");
    printf("\tPRINT 1 TO N NUMBER USING GOTO STATEMENT\n");
    printf("\t----------------------------------------\n");
    printf("\n\n\tENTER N NUMBER ( INTEGER TYPE) : ");
    scanf("%d",&n);
    GOTO_STATEMENT:
        {
            if(i<=n)
            {
                printf("\t%d\n",i);
                i++;
                goto GOTO_STATEMENT;
            }
            else if(i>n)
            {
                exit(1);
            }
        }
    return 0;
}

OUTPUT:

EXPLANATION:

  • #include<stdio.h> is used for input and output functions working purpose.
  • In if-statement, we use printf function to print numbers.
  • i++ is used to increment value.

Leave a comment