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
PROGRAM CODE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Comments
Post a Comment