Pages

Saturday, December 28, 2013

Goto Statement

Write a program to calculate the square root of a Positive number and also handle negative number

Input:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main (void)
{
   float num;
positive:
   printf("Enter a positive number: ");
    scanf("%f", &num);
if (num < 0)
   goto positive;
else
  printf("Square Root of %0.2f is %0.2f", num, sqrt(num));
getch();
}// main

Result:


Enter a positive number: 81
Square Root of 81 is 9


No comments:

Post a Comment