CREATE PROC [DBO].[USP_GETPRIMNUMBERS](@N INT)
AS
BEGIN
DECLARE @I INT=2
DECLARE @FLAG BIT=0
WHILE(@I<@N)
BEGIN
IF(@N%@I=0)
BEGIN
SET @FLAG=1
BREAK
END
SET @I=@I+1
END
IF(@FLAG=1)
BEGIN
PRINT (' THE GIVEN NUMBER IS NOT PRIME')
END
ELSE IF (@FLAG=0)
BEGIN
PRINT (' THE GIVEN NUMBER IS PRIME')
END
END
EXEC [USP_GETPRIMNUMBERS] 2
EXEC [USP_GETPRIMNUMBERS] 3
EXEC [USP_GETPRIMNUMBERS] 5
EXEC [USP_GETPRIMNUMBERS] 8
No comments:
Post a Comment