PERL
34
gcd
Guest on 20th June 2022 04:38:05 PM
#include <stdio.h>
#include <stdlib.h>
unsigned long gcd
(unsigned long x
, unsigned long
y)
{
if (x
> y) x
%= y; else y %= x
;
}
{
printf("Content-type: text/html\n\n");
"<head>\n"
"<title>CGI script for the GCD</title>\n"
"</head>\n"
"<body>\n"
"<h1>Result</h1>\n");
char *data = getenv("QUERY_STRING");
if (data == NULL)
printf("<p>Error! Error in passing data from form to script.</p>");
else if (sscanf
(data
, "x=%lu&y=%lu", &x, &y) != 2)
printf("<p>Error! Invalid parameters. Data must be numeric.</p>");
else
printf("<p>The GCD of %lu and %lu is %lu.</p>\n", x
, y, gcd
(x
, y));
"</html>\n");
}