We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
DELIMITER //
CREATE PROCEDURE p1(IN n INT)
BEGIN
DECLARE i INT DEFAULT 3;
DECLARE result VARCHAR(10000) DEFAULT '2';
DECLARE flag INT DEFAULT 0;
DECLARE j INT;
loop1:LOOP
SET flag = 0;
SET j = i;
loop2:LOOP
SET j = j-1;
IF j = 1 THEN LEAVE loop2;
END IF;
IF i%j = 0 THEN
SET flag = 1;
LEAVE loop2;
END IF;
END LOOP loop2;
IF flag = 0 THEN SET result = CONCAT(result,'&',i);
END IF;
IF i = n THEN LEAVE loop1;
END IF;
SET i = i+1;
END LOOP loop1;
SELECT result;
END //
DELIMITER ;
CALL p1(1000);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
DELIMITER // CREATE PROCEDURE p1(IN n INT) BEGIN DECLARE i INT DEFAULT 3; DECLARE result VARCHAR(10000) DEFAULT '2'; DECLARE flag INT DEFAULT 0; DECLARE j INT; loop1:LOOP SET flag = 0; SET j = i; loop2:LOOP SET j = j-1; IF j = 1 THEN LEAVE loop2; END IF; IF i%j = 0 THEN SET flag = 1; LEAVE loop2; END IF; END LOOP loop2; IF flag = 0 THEN SET result = CONCAT(result,'&',i); END IF; IF i = n THEN LEAVE loop1; END IF; SET i = i+1; END LOOP loop1; SELECT result; END // DELIMITER ;
CALL p1(1000);