C Program code to read & display numbers until a negative number is heaved

This C program code reads and displays a number until a negative number is an input. The program flow starts only when a positive number is entered. This is done with a goto statement. Then the program reads and displays positive numbers and the program terminates when a negative number is entered. The do while statement is used here.


PROGRAM CODE
#include<stdio.h>
int main()
{
int a;
start:
printf("Enter a +ve number to start the program: ");
scanf("%d",&a);
if(a<0)
goto start;
do
{
printf("%d",a);
printf("\tEnter a number: ");
scanf("%d",&a);
}
while(a>=0);
printf("You entered a -ve number. PROGRAM TERMINATING!!!");
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub


Comments