Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Generate a REXX translation of this Python snippet without changing its computational steps.
try: from functools import reduce except: pass def topx(data, tops=None): 'Extract the set of top-level(s) in topological order' for k, v in data.items(): v.discard(k) if tops is None: tops = toplevels(data) return _topx(data, tops, [], set()) def _topx(data, tops, _sofar, _sofar...
parse arg job jobL.=; stage.=; #.=0; @.=; JL= tree.=; tree.1= ' top1 des1 ip1 ip2 ' tree.2= ' top2 des1 ip2 ip3 ' tree.3= ...
Convert the following code from Python to REXX, ensuring the logic remains intact.
import io def sort_large_file(n: int, source: open, sink: open, file_opener = open)->None: mergers = [] while True: text = list(source.read(n)) if not len(text): break; text.sort() merge_me = file_opener() merge_me.write(''.join(text)) ...
parse arg FID n lim seed . if FID=='' | FID=="," then FID= 'SORT_EXT.OUT' if n=='' | n=="," then n= 500 if lim=='' | lim=="," then lim= 10 if datatype(seed, 'W') then call random ,,seed sWork = 'SORTWORK.' call gen n,lim ...
Produce a functionally identical REXX code for the snippet given in Python.
import io def sort_large_file(n: int, source: open, sink: open, file_opener = open)->None: mergers = [] while True: text = list(source.read(n)) if not len(text): break; text.sort() merge_me = file_opener() merge_me.write(''.join(text)) ...
parse arg FID n lim seed . if FID=='' | FID=="," then FID= 'SORT_EXT.OUT' if n=='' | n=="," then n= 500 if lim=='' | lim=="," then lim= 10 if datatype(seed, 'W') then call random ,,seed sWork = 'SORTWORK.' call gen n,lim ...
Rewrite this program in REXX while keeping its functionality equivalent to the Python version.
import sys with open(sys.argv[0],'r') as input: for row in input: print(row, end='')
do j=1 for sourceline() call lineout , sourceline(j) end
Keep all operations the same but rewrite the snippet in REXX.
import requests URL = "http://rosettacode.org/mw/api.php" PARAMS = { "action": "query", "format": "json", "formatversion": 2, "generator": "categorymembers", "gcmtitle": "Category:Language users", "gcmlimit": 500, "prop": "categoryinfo", } def fetch_data(): counts = {} contin...
parse arg catFID lanFID outFID . call init call get call eSort #,0 call tSort call eSort #,1 call out ...
Preserve the algorithm and functionality while converting the code from Python to REXX.
import requests URL = "http://rosettacode.org/mw/api.php" PARAMS = { "action": "query", "format": "json", "formatversion": 2, "generator": "categorymembers", "gcmtitle": "Category:Language users", "gcmlimit": 500, "prop": "categoryinfo", } def fetch_data(): counts = {} contin...
parse arg catFID lanFID outFID . call init call get call eSort #,0 call tSort call eSort #,1 call out ...
Rewrite this program in REXX while keeping its functionality equivalent to the Python version.
from collections import defaultdict def from_edges(edges): class Node: def __init__(self): self.root = None self.succ = [] nodes = defaultdict(Node) for v,w in edges: nodes[v].succ.append(nodes[w]) for i...
g='[2] [3] [1] [2 3 5] [4 6] [3 7] [6] [5 7 8]' gg=g Do i=1 By 1 While gg>'' Parse Var gg '[' g.i ']' gg name.i=i-1 End g.0=i-1 index.=0 lowlink.=0 stacked.=0 stack.=0 x=1 Do n=1 To g.0 If index.n=0 Then If strong_connect(n)=0 Then Return End Exit strong_connect: Procedure Expose x g. index. lowl...
Write a version of this Python function in REXX with identical behavior.
def facpropzeros(N, verbose = True): proportions = [0.0] * N fac, psum = 1, 0.0 for i in range(N): fac *= i + 1 d = list(str(fac)) psum += sum(map(lambda x: x == '0', d)) / len(d) proportions[i] = psum / (i + 1) if verbose: print("The mean proportion of 0 in fact...
parse arg $ if $='' | $="," then $= 100 1000 10000 #= words($) numeric digits 100 big= word($, #); != 1 do i=1 for big ...
Keep all operations the same but rewrite the snippet in REXX.
import math import os def suffize(num, digits=None, base=10): suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'X', 'W', 'V', 'U', 'googol'] exponent_distance = 10 if base == 2 else 3 num = num.strip().replace(',', '') num_sign = num[0] if num[0] in '+-' else '' num = abs(float(num)) ...
@.= parse arg @.1 if @.1=='' then do; @.1= ' 87,654,321 ' @.2= ' -998,877,665,544,332,211,000 3 ' @.3= ' +112,233 0 ...
Rewrite the snippet below in REXX so it works the same as the original Python code.
import math import os def suffize(num, digits=None, base=10): suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'X', 'W', 'V', 'U', 'googol'] exponent_distance = 10 if base == 2 else 3 num = num.strip().replace(',', '') num_sign = num[0] if num[0] in '+-' else '' num = abs(float(num)) ...
@.= parse arg @.1 if @.1=='' then do; @.1= ' 87,654,321 ' @.2= ' -998,877,665,544,332,211,000 3 ' @.3= ' +112,233 0 ...
Port the following code from C# to BBC_Basic with equivalent syntax and logic.
static void Main(string[] args) { int bufferHeight = Console.BufferHeight; int bufferWidth = Console.BufferWidth; int windowHeight = Console.WindowHeight; int windowWidth = Console.WindowWidth; Console.Write("Buffer Height: "); Console.WriteLine(bufferHeight); Console.Write("Buffer Width: "...
dx% = @vdu.tr%-@vdu.tl% : dy% = @vdu.tb%-@vdu.tt% :
Preserve the algorithm and functionality while converting the code from C# to BBC_Basic.
using System; using System.Collections.Generic; using System.Linq; class Program { static void RunCode(string code) { int accumulator = 0; var opcodes = new Dictionary<char, Action> { {'H', () => Console.WriteLine("Hello, World!"))}, {'Q', () => Console.WriteLine...
PROChq9plus("hq9+HqQ+Qq") END DEF PROChq9plus(code$) LOCAL accumulator%, i%, bottles% FOR i% = 1 TO LEN(code$) CASE MID$(code$, i%, 1) OF WHEN "h","H": PRINT "Hello, world!" WHEN "q","Q": PRINT code$ WHEN "9": bottles% = 99 ...
Maintain the same structure and functionality when rewriting this code in BBC_Basic.
using System; using System.Collections.Generic; using System.Linq; class Program { static void RunCode(string code) { int accumulator = 0; var opcodes = new Dictionary<char, Action> { {'H', () => Console.WriteLine("Hello, World!"))}, {'Q', () => Console.WriteLine...
PROChq9plus("hq9+HqQ+Qq") END DEF PROChq9plus(code$) LOCAL accumulator%, i%, bottles% FOR i% = 1 TO LEN(code$) CASE MID$(code$, i%, 1) OF WHEN "h","H": PRINT "Hello, world!" WHEN "q","Q": PRINT code$ WHEN "9": bottles% = 99 ...
Convert this C# snippet to BBC_Basic and keep its semantics consistent.
using System; using System.Linq; using System.Collections.Generic; public struct Card { public Card(string rank, string suit) : this() { Rank = rank; Suit = suit; } public string Rank { get; } public string Suit { get; } public override string ToString() => $"{Rank} of {Suit}"...
DIM Deck{ncards%, card&(51)}, Suit$(3), Rank$(12) Suit$() = "Clubs", "Diamonds", "Hearts", "Spades" Rank$() = "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", \ \ "Eight", "Nine", "Ten", "Jack", "Queen", "King" PRINT "Creating a new deck..." PROCnewdeck(deck1{}) ...
Preserve the algorithm and functionality while converting the code from C# to BBC_Basic.
using System; namespace LastSundayOfEachMonth { class Program { static void Main() { Console.Write("Year to calculate: "); string strYear = Console.ReadLine(); int year = Convert.ToInt32(strYear); DateTime date; for (int i = 1; i <= ...
INSTALL @lib$+"DATELIB" INPUT "What year to calculate (YYYY)? " Year% PRINT '"Last Sundays in ";Year%;" are on:" FOR Month%=1 TO 12 PRINT Year% "-" RIGHT$("0"+STR$Month%,2) "-";FN_dim(Month%,Year%)-FN_dow(FN_mjd(FN_dim(Month%,Year%),Month%,Year%)) NEXT END
Transform the following C# implementation into BBC_Basic, maintaining the same output and logic.
using System; namespace LastSundayOfEachMonth { class Program { static void Main() { Console.Write("Year to calculate: "); string strYear = Console.ReadLine(); int year = Convert.ToInt32(strYear); DateTime date; for (int i = 1; i <= ...
INSTALL @lib$+"DATELIB" INPUT "What year to calculate (YYYY)? " Year% PRINT '"Last Sundays in ";Year%;" are on:" FOR Month%=1 TO 12 PRINT Year% "-" RIGHT$("0"+STR$Month%,2) "-";FN_dim(Month%,Year%)-FN_dow(FN_mjd(FN_dim(Month%,Year%),Month%,Year%)) NEXT END
Translate this program into BBC_Basic but keep the logic exactly as in C#.
using System; using System.Dynamic; using System.Collections.Generic; public class Program { public static void Main() { string varname = Console.ReadLine(); dynamic expando = new ExpandoObject(); var map = expando as IDictionary<string, object>; map.Add(varname, "Hello...
INPUT "Enter a variable name: " name$ INPUT "Enter a numeric value: " numeric$ dummy% = EVAL("FNassign("+name$+","+numeric$+")") PRINT "Variable " name$ " now has the value "; EVAL(name$) END DEF FNassign(RETURN n, v) : n = v : = 0
Rewrite the snippet below in BBC_Basic so it works the same as the original C# code.
using System; using System.Drawing; using System.Windows.Forms; class Program { static Color GetPixel(Point position) { using (var bitmap = new Bitmap(1, 1)) { using (var graphics = Graphics.FromImage(bitmap)) { graphics.CopyFromScreen(position, new Point...
palette_index% = POINT(x%, y%) RGB24b_colour% = TINT(x%, y%)
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C# version.
using System; using System.Threading; using System.Media; class Program { static void Main(string[] args) { SoundPlayer s1 = new SoundPlayer(); s1.SoundLocation = file; s1.Play(); s1.Play(); Thread.Sleep(100); s1.Stop(); ...
SND_LOOP = 8 SND_ASYNC = 1 SND_FILENAME = &20000 PRINT "Playing a MIDI file..." *PLAY C:\windows\media\canyon.mid WAIT 300 PRINT "Playing the Windows TADA sound quietly..." wave$ = "\windows\media\tada.wav" volume% = 10000 SYS "waveOutSetVolume",...
Preserve the algorithm and functionality while converting the code from C# to BBC_Basic.
using static System.Console; using static System.Threading.Thread; using System; public static class PenneysGame { const int pause = 500; const int N = 3; static Random rng = new Random(); static int Toss() => rng.Next(2); static string AsString(this int sequence) { string s = ""; ...
PRINT "*** Penney's Game ***" REPEAT PRINT ' "Heads you pick first, tails I pick first." PRINT "And it is... "; WAIT 100 ht% = RND(0 - TIME) AND 1 IF ht% THEN PRINT "heads!" PROC_player_chooses(player$) computer$ = FN_optimal(player$) PRINT "I choose "; computer$; "." ELSE PRINT "tails!...
Produce a functionally identical BBC_Basic code for the snippet given in C#.
using System.Diagnostics; namespace RC { internal class Program { public static void Main() { string sSource = "Sample App"; string sLog = "Application"; string sEvent = "Hello from RC!"; if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);...
INSTALL @lib$+"COMLIB" PROC_cominitlcid(1033) WshShell% = FN_createobject("WScript.Shell") PROC_callmethod(WshShell%, "LogEvent(0, ""Test from BBC BASIC"")") PROC_releaseobject(WshShell%) PROC_comexit
Can you help me rewrite this code in BBC_Basic instead of C#, keeping it the same logically?
public enum Planet { Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune } [Flags] public enum Days { None = 0, Sunday = 1, Monday = 2, Tuesday = 4, Wednesday = 8, Thursday = 16, Friday = 32, Saturday = 64, Workdays = Monday | Tuesday | Wednesday | Thursday | Friday ...
DEF PROC_foo(bar, baz$(), quux%, RETURN fred%, RETURN jim%)
Can you help me rewrite this code in BBC_Basic instead of C#, keeping it the same logically?
using System; using System.Numerics; namespace LeftFactorial { class Program { static void Main(string[] args) { for (int i = 0; i <= 10; i++) { Console.WriteLine(string.Format("!{0} = {1}", i, LeftFactorial(i))); } for (int j = 2...
INSTALL @lib$+"BB4WMAPMLIB" : PROCMAPM_Init : MAPM_Dec%=200 Result$="0" : A$="1" FOR I%=0 TO 10000 IF I% Result$=FNMAPM_Add(Result$,A$) : A$=FNMAPM_Multiply(A$,STR$I%) IF I% < 111 IF I% MOD 10 = 0 OR I% < 11 PRINT "!";I% " = " FNMAPM_FormatDec(Result$,0) IF I% > 999 IF I...
Port the provided C# code into BBC_Basic while preserving the original functionality.
using System; using System.Numerics; namespace LeftFactorial { class Program { static void Main(string[] args) { for (int i = 0; i <= 10; i++) { Console.WriteLine(string.Format("!{0} = {1}", i, LeftFactorial(i))); } for (int j = 2...
INSTALL @lib$+"BB4WMAPMLIB" : PROCMAPM_Init : MAPM_Dec%=200 Result$="0" : A$="1" FOR I%=0 TO 10000 IF I% Result$=FNMAPM_Add(Result$,A$) : A$=FNMAPM_Multiply(A$,STR$I%) IF I% < 111 IF I% MOD 10 = 0 OR I% < 11 PRINT "!";I% " = " FNMAPM_FormatDec(Result$,0) IF I% > 999 IF I...
Port the provided C# code into BBC_Basic while preserving the original functionality.
using Mpir.NET; using System; using System.Collections.Generic; class MaxLftTrP_B { static void Main() { mpz_t p; var sw = System.Diagnostics.Stopwatch.StartNew(); L(3); for (uint b = 3; b < 13; b++) { sw.Restart(); p = L(b); Console.WriteLine("{0} {1,2} {...
HIMEM = PAGE + 3000000 INSTALL @lib$+"HIMELIB" PROC_himeinit("HIMEkey") DIM old$(20000), new$(20000) h1% = 1 : h2% = 2 : h3% = 3 : h4% = 4 FOR base% = 3 TO 17 PRINT "Base "; base% " : " FN_largest_left_truncated_prime(base%) NEXT END DEF...
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C# version.
using SpeechLib; namespace Speaking_Computer { public class Program { private static void Main() { var voice = new SpVoice(); voice.Speak("This is an example of speech synthesis."); } } }
SPF_ASYNC = 1 ON ERROR SYS `CoUninitialize` : PRINT 'REPORT$ : END ON CLOSE SYS `CoUninitialize` : QUIT SYS "LoadLibrary","OLE32.DLL" TO O% SYS "GetProcAddress",O%,"CoInitialize" TO `CoInitialize` SYS "GetProcAddress",O%,"CoUninitialize" TO `CoUninitialize` SYS "GetProcA...
Write the same algorithm in COBOL as shown in this C implementation.
if (strcmp(a,b)) action_on_equality();
"hello" = "hello" "helloo" <> "hello" "aello" < "hello"
Change the programming language of this snippet from C to COBOL without modifying what it does.
#include <stdio.h> #include <stdbool.h> #include <locale.h> bool isPrime(int n) { int d; if (n < 2) return false; if (!(n%2)) return n == 2; if (!(n%3)) return n == 3; d = 5; while (d*d <= n) { if (!(n%d)) return false; d += 2; if (!(n%d)) return false; d += 4; ...
IDENTIFICATION DIVISION. PROGRAM-ID. N3-PLUS-2-PRIMES. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 N PIC 9(3). 03 N3PLUS2 PIC 9(7). 03 DIVISOR PIC 9(4). 03 DIV-SQ PIC 9(8). ...
Maintain the same structure and functionality when rewriting this code in COBOL.
#include <stdio.h> #include <stdbool.h> #include <locale.h> bool isPrime(int n) { int d; if (n < 2) return false; if (!(n%2)) return n == 2; if (!(n%3)) return n == 3; d = 5; while (d*d <= n) { if (!(n%d)) return false; d += 2; if (!(n%d)) return false; d += 4; ...
IDENTIFICATION DIVISION. PROGRAM-ID. N3-PLUS-2-PRIMES. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 N PIC 9(3). 03 N3PLUS2 PIC 9(7). 03 DIVISOR PIC 9(4). 03 DIV-SQ PIC 9(8). ...
Port the following code from C to COBOL with equivalent syntax and logic.
#include<stdio.h> long long seed; long long random(){ seed = seed * seed / 1000 % 1000000; return seed; } int main(){ seed = 675248; for(int i=1;i<=5;i++) printf("%lld\n",random()); return 0; }
IDENTIFICATION DIVISION. PROGRAM-ID. MIDDLE-SQUARE. DATA DIVISION. WORKING-STORAGE SECTION. 01 STATE. 03 SEED PIC 9(6) VALUE 675248. 03 SQUARE PIC 9(12). 03 FILLER REDEFINES SQUARE. 05 FILLER PIC 9(3). ...
Please provide an equivalent version of this C code in COBOL.
#include<stdio.h> long long seed; long long random(){ seed = seed * seed / 1000 % 1000000; return seed; } int main(){ seed = 675248; for(int i=1;i<=5;i++) printf("%lld\n",random()); return 0; }
IDENTIFICATION DIVISION. PROGRAM-ID. MIDDLE-SQUARE. DATA DIVISION. WORKING-STORAGE SECTION. 01 STATE. 03 SEED PIC 9(6) VALUE 675248. 03 SQUARE PIC 9(12). 03 FILLER REDEFINES SQUARE. 05 FILLER PIC 9(3). ...
Keep all operations the same but rewrite the snippet in COBOL.
#include <stdio.h> extern int Query (char * Data, size_t * Length); int main (int argc, char * argv []) { char Buffer [1024]; size_t Size = sizeof (Buffer); if (0 == Query (Buffer, &Size)) { printf ("failed to call Query\n"); } else { char * Ptr = Buffer; while (Size--...
identification division. program-id. Query. environment division. configuration section. special-names. call-convention 0 is extern. repository. function all intrinsic. data division. working-storage section. 01 query-result. ...
Port the following code from C to COBOL with equivalent syntax and logic.
#include<conio.h> #define COLOURS 8 int main() { int colour=0,i,j,MAXROW,MAXCOL; struct text_info tInfo; gettextinfo(&tInfo); MAXROW = tInfo.screenheight; MAXCOL = tInfo.screenwidth; textbackground(BLACK); clrscr(); for(colour=0;colour<COLOURS;colour++) { getch(); got...
IDENTIFICATION DIVISION. PROGRAM-ID. terminal-colour-bars. DATA DIVISION. WORKING-STORAGE SECTION. 01 width PIC 9(3). 01 height PIC 9(3). 01 interval PIC 9(3). 01 colours-area. 03 colour-values. 05 FILLE...
Convert the following code from C to COBOL, ensuring the logic remains intact.
#include<conio.h> #define COLOURS 8 int main() { int colour=0,i,j,MAXROW,MAXCOL; struct text_info tInfo; gettextinfo(&tInfo); MAXROW = tInfo.screenheight; MAXCOL = tInfo.screenwidth; textbackground(BLACK); clrscr(); for(colour=0;colour<COLOURS;colour++) { getch(); got...
IDENTIFICATION DIVISION. PROGRAM-ID. terminal-colour-bars. DATA DIVISION. WORKING-STORAGE SECTION. 01 width PIC 9(3). 01 height PIC 9(3). 01 interval PIC 9(3). 01 colours-area. 03 colour-values. 05 FILLE...
Convert the following code from C to COBOL, ensuring the logic remains intact.
#define PI 3.14159265358979323 #define MINSIZE 10 #define MAXSIZE 100
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9.
Change the programming language of this snippet from C to COBOL without modifying what it does.
#include <stdbool.h> #include <stdio.h> bool isPrime(int n) { if (n < 0) { n = -n; } return n == 2 || n == 3 || n == 5 || n == 7; } int main() { int count = 0; int i, j; int d[3]; int dptr; printf("Strange numbers in the open interval (100, 500) are:\n"); for (i = 101; i <...
IDENTIFICATION DIVISION. PROGRAM-ID. STRANGE-NUMBERS. DATA DIVISION. WORKING-STORAGE SECTION. 01 COMPUTATION. 02 NUM PIC 999. 02 DIGITS REDEFINES NUM PIC 9 OCCURS 3 TIMES. 02 DIGIT-PRIME PIC 9. 88 PRIME ...
Please provide an equivalent version of this C code in COBOL.
#include <stdbool.h> #include <stdio.h> bool isPrime(int n) { if (n < 0) { n = -n; } return n == 2 || n == 3 || n == 5 || n == 7; } int main() { int count = 0; int i, j; int d[3]; int dptr; printf("Strange numbers in the open interval (100, 500) are:\n"); for (i = 101; i <...
IDENTIFICATION DIVISION. PROGRAM-ID. STRANGE-NUMBERS. DATA DIVISION. WORKING-STORAGE SECTION. 01 COMPUTATION. 02 NUM PIC 999. 02 DIGITS REDEFINES NUM PIC 9 OCCURS 3 TIMES. 02 DIGIT-PRIME PIC 9. 88 PRIME ...
Convert this C block to COBOL, preserving its control flow and logic.
#include <stdio.h> int main() { int intspace; int *address; address = &intspace; *address = 65535; printf("%p: %08x (=%08x)\n", address, *address, intspace); *((char*)address) = 0x00; *((char*)address+1) = 0x00; *((char*)address+2) = 0xff; *((char*)address+3) = 0xff; printf("%p: %08x (=%08...
IDENTIFICATION DIVISION. PROGRAM-ID. object-address-test. DATA DIVISION. LOCAL-STORAGE SECTION. 01 int-space. 05 val PICTURE 9(5) VALUE 12345. 01 addr BASED. 05 val PICTURE 9(5) VALUE ZERO. 01 point USAGE POINTER. PROCEDURE DIVISION. D...
Translate the given C code snippet into COBOL without altering its behavior.
#include <stdio.h> #include <stdlib.h> #define N 100000 int main() { int i, flip, *q = (int*)malloc(sizeof(int) * N) - 1; q[1] = q[2] = 1; for (i = 3; i <= N; i++) q[i] = q[i - q[i - 1]] + q[i - q[i - 2]]; for (i = 1; i <= 10; i++) printf("%d%c", q[i], i == 10 ? '\n' : ' '); printf("%d\n", q[1000]); f...
IDENTIFICATION DIVISION. PROGRAM-ID. Q-SEQ. DATA DIVISION. WORKING-STORAGE SECTION. 01 SEQ. 02 Q PIC 9(3) OCCURS 1000 TIMES. 02 Q-TMP1 PIC 9(3). 02 Q-TMP2 PIC 9(3). 02 N PIC 9(4). 01 DISPLAYING. ...
Ensure the translated COBOL code behaves exactly like the original C snippet.
#include <stdio.h> #include <stdlib.h> #define N 100000 int main() { int i, flip, *q = (int*)malloc(sizeof(int) * N) - 1; q[1] = q[2] = 1; for (i = 3; i <= N; i++) q[i] = q[i - q[i - 1]] + q[i - q[i - 2]]; for (i = 1; i <= 10; i++) printf("%d%c", q[i], i == 10 ? '\n' : ' '); printf("%d\n", q[1000]); f...
IDENTIFICATION DIVISION. PROGRAM-ID. Q-SEQ. DATA DIVISION. WORKING-STORAGE SECTION. 01 SEQ. 02 Q PIC 9(3) OCCURS 1000 TIMES. 02 Q-TMP1 PIC 9(3). 02 Q-TMP2 PIC 9(3). 02 N PIC 9(4). 01 DISPLAYING. ...
Translate the given C code snippet into COBOL without altering its behavior.
#include <stdio.h> #include <string.h> int match(const char *s, const char *p, int overlap) { int c = 0, l = strlen(p); while (*s != '\0') { if (strncmp(s++, p, l)) continue; if (!overlap) s += l - 1; c++; } return c; } int main() { ...
IDENTIFICATION DIVISION. PROGRAM-ID. testing. DATA DIVISION. WORKING-STORAGE SECTION. 01 occurrences PIC 99. PROCEDURE DIVISION. INSPECT "the three truths" TALLYING occurrences FOR ALL "th" DISPLAY occurrences MOVE 0 TO occurrenc...
Preserve the algorithm and functionality while converting the code from C to COBOL.
#include <stdio.h> #include <mpfr.h> void h(int n) { MPFR_DECL_INIT(a, 200); MPFR_DECL_INIT(b, 200); mpfr_fac_ui(a, n, MPFR_RNDD); mpfr_set_ui(b, 2, MPFR_RNDD); mpfr_log(b, b, MPFR_RNDD); mpfr_pow_ui(b, b, n + 1, MPFR_RNDD); mpfr_div(a, a, b, MPFR_RNDD); mpfr_div_ui(a, a, 2, MPFR_RNDD); mpfr_fra...
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. hickerson-series. ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. FUNCTION ALL INTRINSIC . DATA DIVISION. WORKING-STORAGE SECTION. 01 n PIC 99 COMP. 01 h PIC Z(19)9.9(10). ...
Keep all operations the same but rewrite the snippet in COBOL.
#include <stdio.h> #include <mpfr.h> void h(int n) { MPFR_DECL_INIT(a, 200); MPFR_DECL_INIT(b, 200); mpfr_fac_ui(a, n, MPFR_RNDD); mpfr_set_ui(b, 2, MPFR_RNDD); mpfr_log(b, b, MPFR_RNDD); mpfr_pow_ui(b, b, n + 1, MPFR_RNDD); mpfr_div(a, a, b, MPFR_RNDD); mpfr_div_ui(a, a, 2, MPFR_RNDD); mpfr_fra...
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. hickerson-series. ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. FUNCTION ALL INTRINSIC . DATA DIVISION. WORKING-STORAGE SECTION. 01 n PIC 99 COMP. 01 h PIC Z(19)9.9(10). ...
Change the programming language of this snippet from C to COBOL without modifying what it does.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <confini.h> #define rosetta_uint8_t unsigned char #define FALSE 0 #define TRUE 1 #define CONFIGS_TO_READ 5 #define INI_ARRAY_DELIMITER ',' struct configs { char *fullname; char *favouritefruit; rosetta_uint8_t needspeeling; rosetta_uint8_t see...
identification division. program-id. ReadConfiguration. environment division. configuration section. repository. function all intrinsic. input-output section. file-control. select config-file assign to "Configuration.txt" ...
Produce a language-to-language conversion: from C to COBOL, same semantics.
#include <stdbool.h> #include <stdio.h> #include <string.h> void memoizeIsPrime( bool * result, const int N ) { result[2] = true; result[3] = true; int prime[N]; prime[0] = 3; int end = 1; for (int n = 5; n < N; n += 2) { bool n_is_prime = true; for (int i = 0; i < end; ++i)...
IDENTIFICATION DIVISION. PROGRAM-ID. ADDITIVE-PRIMES. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 MAXIMUM PIC 999. 03 AMOUNT PIC 999. 03 CANDIDATE PIC 999. 03 DIGIT PIC 9 OCCURS 3...
Change the following C code into COBOL without altering its purpose.
#include <stdio.h> #define SWAP(r,s) do{ t=r; r=s; s=t; } while(0) void StoogeSort(int a[], int i, int j) { int t; if (a[j] < a[i]) SWAP(a[i], a[j]); if (j - i > 1) { t = (j - i + 1) / 3; StoogeSort(a, i, j - t); StoogeSort(a, i + t, j); StoogeSort(a, i, j - t); } } ...
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. stooge-sort-test. DATA DIVISION. WORKING-STORAGE SECTION. 01 Arr-Len CONSTANT 7. 01 arr-area VALUE "00004001000020000005000230000000000". 03 arr-elt PIC 9(5) OCCURS Arr-Len T...
Change the following C code into COBOL without altering its purpose.
#include <stdio.h> void shell_sort (int *a, int n) { int h, i, j, t; for (h = n; h /= 2;) { for (i = h; i < n; i++) { t = a[i]; for (j = i; j >= h && t < a[j - h]; j -= h) { a[j] = a[j - h]; } a[j] = t; } } } int main (int ac,...
******************************************************* IDENTIFICATION DIVISION. ******************************************************* PROGRAM-ID. SHELLSRT. **********************...
Write a version of this C function in COBOL with identical behavior.
#include<stdio.h> #include<stdlib.h> #include<math.h> int sum5( int n ) { if(n<10) return pow(n,5); return pow(n%10,5) + sum5(n/10); } int main(void) { int i, sum = 0; for(i=2;i<=999999;i++) { if(i==sum5(i)) { printf( "%d\n", i ); sum+=i; } } printf( "To...
IDENTIFICATION DIVISION. PROGRAM-ID. DIGIT-FIFTH-POWER. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(6). 03 MAXIMUM PIC 9(6). 03 DIGITS PIC 9 OCCURS 6 TIMES, REDE...
Maintain the same structure and functionality when rewriting this code in COBOL.
#include<stdio.h> #include<stdlib.h> #include<math.h> int sum5( int n ) { if(n<10) return pow(n,5); return pow(n%10,5) + sum5(n/10); } int main(void) { int i, sum = 0; for(i=2;i<=999999;i++) { if(i==sum5(i)) { printf( "%d\n", i ); sum+=i; } } printf( "To...
IDENTIFICATION DIVISION. PROGRAM-ID. DIGIT-FIFTH-POWER. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(6). 03 MAXIMUM PIC 9(6). 03 DIGITS PIC 9 OCCURS 6 TIMES, REDE...
Generate a COBOL translation of this C snippet without changing its computational steps.
#include <stdio.h> int main() { int max = 0, i = 0, sixes, nines, twenties; loopstart: while (i < 100) { for (sixes = 0; sixes*6 < i; sixes++) { if (sixes*6 == i) { i++; goto loopstart; } for (nines = 0; nines*9 < i; nines++) { ...
IDENTIFICATION DIVISION. PROGRAM-ID. MCNUGGETS. DATA DIVISION. WORKING-STORAGE SECTION. 01 NUGGETS. 03 NUGGET-FLAGS PIC X OCCURS 100 TIMES. 88 IS-NUGGET VALUE 'X'. 01 A PIC 999. 01 B PIC 999. 01...
Write the same algorithm in COBOL as shown in this C implementation.
#include <stdio.h> int main(int argc, char const *argv[]) { for (char c = 0x41; c < 0x5b; c ++) putchar(c); putchar('\n'); for (char c = 0x61; c < 0x7b; c ++) putchar(c); putchar('\n'); return 0; }
identification division. program-id. determine. environment division. configuration section. repository. function all intrinsic. data division. working-storage section. 01 tx pic x. 01 lower-8bit pic x(256). 01 upper-8bit pic x(256). ...
Change the programming language of this snippet from C to COBOL without modifying what it does.
#include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdio.h> #define TRUE 1 #define FALSE 0 #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) double jaro(const char *str1, const char *str2) { int str1_len = strlen(str1); int str2_len = strlen(str2)...
identification division. program-id. JaroDistance. environment division. configuration section. repository. function length intrinsic function trim intrinsic function max intrinsic function min intrinsic . data division...
Write the same algorithm in COBOL as shown in this C implementation.
#include <stdio.h> #define N_COND 3 #define COND_LEN (1 << N_COND) struct { const char *str, *truth;} cond[N_COND] = { {"Printer does not print", "1111...."}, {"A red light is flashing", "11..11.."}, {"Printer is unrecognised", "1.1.1.1."}, }, solu[] = { {"Check the power cable", "..1....."}, {"Check the pr...
>> SOURCE FORMAT FREE identification division. program-id. 'decisiontable'. environment division. configuration section. repository. function all intrinsic. data division. working-storage section. 01 conditions. 03 notprinting pic x. 03 flashing pic x. 03 notrecognized pic x. procedure ...
Convert the following code from C to COBOL, ensuring the logic remains intact.
#include <stdio.h> int divisible(int n) { int p = 1; int c, d; for (c=n; c; c /= 10) { d = c % 10; if (!d || n % d) return 0; p *= d; } return n % p; } int main() { int n, c=0; for (n=1; n<1000; n++) { if (divisible(n)) { printf("%...
IDENTIFICATION DIVISION. PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD. DATA DIVISION. WORKING-STORAGE SECTION. 01 CALCULATION. 02 N PIC 9(4). 02 DGT-PROD PIC 9(3). 02 NSTART PIC 9. 02 D PIC 9. ...
Rewrite this program in COBOL while keeping its functionality equivalent to the C version.
#define _XOPEN_SOURCE #include <stdio.h> #include <time.h> int main() { struct tm t[2]; strptime("2021-12-25", "%F", &t[0]); strptime("2022-01-01", "%F", &t[1]); for (int i=0; i<2; i++) { char buf[32]; strftime(buf, 32, "%F is a %A", &t[i]); puts(buf); } return 0; }
IDENTIFICATION DIVISION. PROGRAM-ID. XMASNY. DATA DIVISION. WORKING-STORAGE SECTION. 01 WEEKDAYS. 03 DAY-NAMES. 05 FILLER PIC X(9) VALUE "Saturday ". 05 FILLER PIC X(9) VALUE "Sunday ". 05 FILLER PIC X(9) VALUE "Monday ...
Port the provided C code into COBOL while preserving the original functionality.
while(1) puts("SPAM");
IDENTIFICATION DIVISION. PROGRAM-ID. Spam. PROCEDURE DIVISION. PERFORM UNTIL 1 <> 1 DISPLAY "SPAM" END-PERFORM GOBACK .
Generate a COBOL translation of this C snippet without changing its computational steps.
double multiply(double a, double b) { return a * b; }
IDENTIFICATION DIVISION. PROGRAM-ID. myTest. DATA DIVISION. WORKING-STORAGE SECTION. 01 x PIC 9(3) VALUE 3. 01 y PIC 9(3) VALUE 2. 01 z PIC 9(9). PROCEDURE DIVISION. CALL "myMultiply" USING BY CONTENT x, BY CONTENT y, ...
Port the following code from C to COBOL with equivalent syntax and logic.
#include <sys/ioctl.h> #include <err.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> int main() { struct winsize ws; int fd; fd = open("/dev/tty", O_RDWR); if (fd < 0) err(1, "/dev/tty"); if (ioctl(fd, TIOCGWINSZ, &ws) < 0) err(1, "/dev/tty"); printf("%d rows by %d columns\n", ws.ws...
IDENTIFICATION DIVISION. PROGRAM-ID. terminal-dimensions. DATA DIVISION. WORKING-STORAGE SECTION. 01 num-lines PIC 9(3). 01 num-cols PIC 9(3). SCREEN SECTION. 01 display-screen. 03 LINE 01 COL 01 PIC 9(3) FROM num-lines. 03 LINE 01 CO...
Keep all operations the same but rewrite the snippet in COBOL.
#include <stdio.h> #include <string.h> int digitSum(int n) { int s = 0; do {s += n % 10;} while (n /= 10); return s; } int digitSumIsSubstring(int n) { char s_n[32], s_ds[32]; sprintf(s_n, "%d", n); sprintf(s_ds, "%d", digitSum(n)); return strstr(s_n, s_ds) != NULL; } int main() { int...
IDENTIFICATION DIVISION. PROGRAM-ID. SUM-SUBSTRING. DATA DIVISION. WORKING-STORAGE SECTION. 01 CALCULATION. 02 N PIC 9999. 02 X PIC 9. 02 DSUM PIC 99. 02 N-DIGITS REDEFINES N. 03 ND P...
Preserve the algorithm and functionality while converting the code from C to COBOL.
#include <stdio.h> #include <string.h> int digitSum(int n) { int s = 0; do {s += n % 10;} while (n /= 10); return s; } int digitSumIsSubstring(int n) { char s_n[32], s_ds[32]; sprintf(s_n, "%d", n); sprintf(s_ds, "%d", digitSum(n)); return strstr(s_n, s_ds) != NULL; } int main() { int...
IDENTIFICATION DIVISION. PROGRAM-ID. SUM-SUBSTRING. DATA DIVISION. WORKING-STORAGE SECTION. 01 CALCULATION. 02 N PIC 9999. 02 X PIC 9. 02 DSUM PIC 99. 02 N-DIGITS REDEFINES N. 03 ND P...
Generate an equivalent COBOL version of this C code.
#include<stdio.h> int main() { FILE* fp = fopen("TAPE.FILE","w"); fprintf(fp,"This code should be able to write a file to magnetic tape.\n"); fprintf(fp,"The Wikipedia page on Magnetic tape data storage shows that magnetic tapes are still in use.\n"); fprintf(fp,"In fact, the latest format, at the time of writin...
>>SOURCE FORMAT IS FREE IDENTIFICATION DIVISION. PROGRAM-ID. MAKE-TAPE-FILE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TAPE-FILE ASSIGN "./TAPE.FILE" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD TAPE-FILE. 01 TAPE-FILE-RECORD PIC X(51). PROCEDURE ...
Write the same code in COBOL as shown below in C.
#include <stdio.h> #include <stdlib.h> #include <gmodule.h> typedef int bool; int main() { int i, n, k = 0, next, *a; bool foundDup = FALSE; gboolean alreadyUsed; GHashTable* used = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable* used1000 = g_hash_table_new(g_direct_hash, g_direct_equ...
IDENTIFICATION DIVISION. PROGRAM-ID. RECAMAN. DATA DIVISION. WORKING-STORAGE SECTION. 01 RECAMAN-SEQUENCE COMP. 02 A PIC 999 OCCURS 99 TIMES INDEXED BY I. 02 N PIC 999 VALUE 0. 01 VARIABLES COMP. 02 ADDC PIC S...
Produce a language-to-language conversion: from C to COBOL, same semantics.
#include <stdio.h> #include <stdlib.h> #include <gmodule.h> typedef int bool; int main() { int i, n, k = 0, next, *a; bool foundDup = FALSE; gboolean alreadyUsed; GHashTable* used = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable* used1000 = g_hash_table_new(g_direct_hash, g_direct_equ...
IDENTIFICATION DIVISION. PROGRAM-ID. RECAMAN. DATA DIVISION. WORKING-STORAGE SECTION. 01 RECAMAN-SEQUENCE COMP. 02 A PIC 999 OCCURS 99 TIMES INDEXED BY I. 02 N PIC 999 VALUE 0. 01 VARIABLES COMP. 02 ADDC PIC S...
Generate a COBOL translation of this C snippet without changing its computational steps.
#include <stdio.h> #include <stdlib.h> void bead_sort(int *a, int len) { int i, j, max, sum; unsigned char *beads; # define BEAD(i, j) beads[i * max + j] for (i = 1, max = a[0]; i < len; i++) if (a[i] > max) max = a[i]; beads = calloc(1, max * len); for (i = 0; i < len; i++) for (j = 0; j < a[i]; j++) ...
>>SOURCE FORMAT FREE identification division. program-id. beadsort. environment division. configuration section. repository. function all intrinsic. data division. working-storage section. 01 filler. 03 row occurs 9 pic x(9). 03 r pic 99. 03 r1 pic 99. 03 r2 pic 99. 03 pole pic 99. ...
Translate this program into COBOL but keep the logic exactly as in C.
void runCode(const char *code) { int c_len = strlen(code); int i, bottles; unsigned accumulator=0; for(i=0;i<c_len;i++) { switch(code[i]) { case 'Q': printf("%s\n", code); break; case 'H': printf("Hello, world!\...
IDENTIFICATION DIVISION. PROGRAM-ID. Exec-Hq9. DATA DIVISION. LOCAL-STORAGE SECTION. 78 Code-Length VALUE 256. 01 i PIC 999. 01 accumulator PIC 999. 01 bottles PIC 999. LINKAGE SECTION. 01 hq9-code PIC X(Code-Length). ...
Produce a language-to-language conversion: from C to COBOL, same semantics.
void runCode(const char *code) { int c_len = strlen(code); int i, bottles; unsigned accumulator=0; for(i=0;i<c_len;i++) { switch(code[i]) { case 'Q': printf("%s\n", code); break; case 'H': printf("Hello, world!\...
IDENTIFICATION DIVISION. PROGRAM-ID. Exec-Hq9. DATA DIVISION. LOCAL-STORAGE SECTION. 78 Code-Length VALUE 256. 01 i PIC 999. 01 accumulator PIC 999. 01 bottles PIC 999. LINKAGE SECTION. 01 hq9-code PIC X(Code-Length). ...
Transform the following C implementation into COBOL, maintaining the same output and logic.
#include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; for (; (n & 1) == 0; n >>= 1) { ++total; } for (unsigned int p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } ...
IDENTIFICATION DIVISION. PROGRAM-ID. TAU-FUNCTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 TAU-VARS. 03 TOTAL PIC 999. 03 N PIC 999. 03 FILLER REDEFINES N. 05 FILLER PIC 99. ...
Produce a functionally identical COBOL code for the snippet given in C.
#include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; for (; (n & 1) == 0; n >>= 1) { ++total; } for (unsigned int p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } ...
IDENTIFICATION DIVISION. PROGRAM-ID. TAU-FUNCTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 TAU-VARS. 03 TOTAL PIC 999. 03 N PIC 999. 03 FILLER REDEFINES N. 05 FILLER PIC 99. ...
Translate the given C code snippet into COBOL without altering its behavior.
#include <stdio.h> #include <stdlib.h> int* mertens_numbers(int max) { int* m = malloc((max + 1) * sizeof(int)); if (m == NULL) return m; m[1] = 1; for (int n = 2; n <= max; ++n) { m[n] = 1; for (int k = 2; k <= n; ++k) m[n] -= m[n/k]; } return m; } int main...
IDENTIFICATION DIVISION. PROGRAM-ID. MERTENS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 M PIC S99 OCCURS 1000 TIMES. 03 N PIC 9(4). 03 K PIC 9(4). 03 V PIC 9(4). 03 IS-ZE...
Keep all operations the same but rewrite the snippet in COBOL.
#include <math.h> #include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; unsigned int p; for (; (n & 1) == 0; n >>= 1) { ++total; } for (p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ...
IDENTIFICATION DIVISION. PROGRAM-ID. PRODUCT-OF-DIVISORS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 DIVISOR-PRODUCTS PIC 9(9) OCCURS 50 TIMES. 03 NUM PIC 999. 03 MUL PIC 999. 01 OUTPUT-FORM...
Translate this program into COBOL but keep the logic exactly as in C.
#include <math.h> #include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; unsigned int p; for (; (n & 1) == 0; n >>= 1) { ++total; } for (p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ...
IDENTIFICATION DIVISION. PROGRAM-ID. PRODUCT-OF-DIVISORS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 DIVISOR-PRODUCTS PIC 9(9) OCCURS 50 TIMES. 03 NUM PIC 999. 03 MUL PIC 999. 01 OUTPUT-FORM...
Change the programming language of this snippet from C to COBOL without modifying what it does.
#include <stdio.h> #include <stdlib.h> #include <locale.h> int locale_ok = 0; wchar_t s_suits[] = L"♠♥♦♣"; const char *s_suits_ascii[] = { "S", "H", "D", "C" }; const char *s_nums[] = { "WHAT", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "OVERFLOW" }; typedef struct { int suit, number, _s;...
identification division. program-id. playing-cards. environment division. configuration section. repository. function all intrinsic. data division. working-storage section. 77 card usage index. 01 deck. 05 cards occurs 52 ...
Preserve the algorithm and functionality while converting the code from C to COBOL.
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + ...
program-id. last-sun. data division. working-storage section. 1 wk-date. 2 yr pic 9999. 2 mo pic 99 value 1. 2 da pic 99 value 1. 1 rd-date redefines wk-date pic 9(8). 1 binary. 2 int-date pic 9(8). 2 dow pic 9(4). 2 sunday pic 9(...
Generate an equivalent COBOL version of this C code.
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + ...
program-id. last-sun. data division. working-storage section. 1 wk-date. 2 yr pic 9999. 2 mo pic 99 value 1. 2 da pic 99 value 1. 1 rd-date redefines wk-date pic 9(8). 1 binary. 2 int-date pic 9(8). 2 dow pic 9(4). 2 sunday pic 9(...
Transform the following C implementation into COBOL, maintaining the same output and logic.
#include <stdio.h> #include <math.h> int main() { int i, p, low, high, pow = 1, osc; int oddSq[120]; for (p = 0; p < 5; ++p) { low = (int)ceil(sqrt((double)pow)); if (!(low%2)) ++low; pow *= 10; high = (int)sqrt((double)pow); for (i = low, osc = 0; i <= high; i += 2)...
IDENTIFICATION DIVISION. PROGRAM-ID. ODD-AND-SQUARE. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 N PIC 999. 03 SQR PIC 9999 VALUE 0. 03 FILLER REDEFINES SQR. 05 FILLER PIC 999. ...
Write the same code in COBOL as shown below in C.
#include <stdio.h> #include <stdbool.h> int digit_sum(int n) { int sum; for (sum = 0; n; n /= 10) sum += n % 10; return sum; } bool prime(int n) { if (n<4) return n>=2; for (int d=2; d*d <= n; d++) if (n%d == 0) return false; return true; } int main() { for (int i=1; i<100; i++) ...
IDENTIFICATION DIVISION. PROGRAM-ID. SQUARE-CUBE-DIGITS-PRIME. DATA DIVISION. WORKING-STORAGE SECTION. 01 NUMBER-SEARCH-VARS. 03 CAND PIC 9(6). 03 SQUARE PIC 9(6). 03 CUBE PIC 9(6). 01 SUM-DIGITS...
Can you help me rewrite this code in COBOL instead of C, keeping it the same logically?
#include <stdio.h> #include <stdbool.h> #include <math.h> #define MAX 1000 void sieve(int n, bool *prime) { prime[0] = prime[1] = false; for (int i=2; i<=n; i++) prime[i] = true; for (int p=2; p*p<=n; p++) if (prime[p]) for (int c=p*p; c<=n; c+=p) prime[c] = false; } bool square(int ...
IDENTIFICATION DIVISION. PROGRAM-ID. SQUARE-PLUS-1-PRIME. DATA DIVISION. WORKING-STORAGE SECTION. 01 N PIC 999. 01 P PIC 9999 VALUE ZERO. 01 PRIMETEST. 03 DSOR PIC 9999. 03 PRIME-FLAG PIC X...
Write a version of this C function in COBOL with identical behavior.
#include <stdio.h> #include <stdbool.h> #include <math.h> #define MAX 1000 void sieve(int n, bool *prime) { prime[0] = prime[1] = false; for (int i=2; i<=n; i++) prime[i] = true; for (int p=2; p*p<=n; p++) if (prime[p]) for (int c=p*p; c<=n; c+=p) prime[c] = false; } bool square(int ...
IDENTIFICATION DIVISION. PROGRAM-ID. SQUARE-PLUS-1-PRIME. DATA DIVISION. WORKING-STORAGE SECTION. 01 N PIC 999. 01 P PIC 9999 VALUE ZERO. 01 PRIMETEST. 03 DSOR PIC 9999. 03 PRIME-FLAG PIC X...
Ensure the translated COBOL code behaves exactly like the original C snippet.
#include <stdio.h> void f(int n) { int i = 1; if (n < 1) { return; } while (1) { int sq = i * i; while (sq > n) { sq /= 10; } if (sq == n) { printf("%3d %9d %4d\n", n, i * i, i); return; } i++; } } int main...
IDENTIFICATION DIVISION. PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N. DATA DIVISION. WORKING-STORAGE SECTION. 01 N PIC 99. 01 SQUARE-NO PIC 999. 01 SQUARE PIC 9(5). 01 OUT-FMT PIC Z(4)9. PROCEDURE DIVISION. BEGIN. ...
Port the following code from C to COBOL with equivalent syntax and logic.
#include <stdio.h> void f(int n) { int i = 1; if (n < 1) { return; } while (1) { int sq = i * i; while (sq > n) { sq /= 10; } if (sq == n) { printf("%3d %9d %4d\n", n, i * i, i); return; } i++; } } int main...
IDENTIFICATION DIVISION. PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N. DATA DIVISION. WORKING-STORAGE SECTION. 01 N PIC 99. 01 SQUARE-NO PIC 999. 01 SQUARE PIC 9(5). 01 OUT-FMT PIC Z(4)9. PROCEDURE DIVISION. BEGIN. ...
Rewrite the snippet below in COBOL so it works the same as the original C code.
#include <stdio.h> #include <sys/mman.h> #include <string.h> int test (int a, int b) { char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3}; void *buf; int c; buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON,-1,0); memcpy (buf, code, sizeof(code...
>>SOURCE FORMAT IS FIXED IDENTIFICATION DIVISION. PROGRAM-ID. MC. DATA DIVISION. WORKING-STORAGE SECTION. 01 INSTRUCTIONS. 03 USAGE BINARY-CHAR UNSIGNED VALUE H'55'. 03 USAGE BINARY-CHAR UNSIGNED VALUE H'48'. 03 USAGE BINARY-CHAR UN...
Generate an equivalent COBOL version of this C code.
#include<stdio.h> #include<stdlib.h> #define min(a, b) (a<=b?a:b) void minab( unsigned int n ) { int i, j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf( "%2d ", min( min(i, n-1-i), min(j, n-1-j) )); } printf( "\n" ); } return; } int main(void) { minab(10); ...
IDENTIFICATION DIVISION. PROGRAM-ID. MINIMUM-CELLS-N-BY-N. DATA DIVISION. WORKING-STORAGE SECTION. 01 TABLE-SIZE PIC 99 VALUE 10. 01 X PIC 99. 01 Y PIC 99. 01 ITEM PIC 99. 01 MIN PIC ...
Please provide an equivalent version of this C code in COBOL.
#include <stdio.h> static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0}; int isstrange(long n) { if (n < 10) return 0; for (; n >= 10; n /= 10) { if (!p[n%10 + (n/10)%10]) return 0; } return 1; } int main(void) { long n; int k = 0; for ...
IDENTIFICATION DIVISION. PROGRAM-ID. STRANGE-PLUS-NUMBERS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 999. 03 DIGITS REDEFINES CANDIDATE, PIC 9 OCCURS 3 TIMES. 03 LEFT...
Translate the given C code snippet into COBOL without altering its behavior.
#include <stdio.h> static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0}; int isstrange(long n) { if (n < 10) return 0; for (; n >= 10; n /= 10) { if (!p[n%10 + (n/10)%10]) return 0; } return 1; } int main(void) { long n; int k = 0; for ...
IDENTIFICATION DIVISION. PROGRAM-ID. STRANGE-PLUS-NUMBERS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 999. 03 DIGITS REDEFINES CANDIDATE, PIC 9 OCCURS 3 TIMES. 03 LEFT...
Convert this C block to COBOL, preserving its control flow and logic.
#include <stdio.h> unsigned digit_sum(unsigned n) { unsigned sum = 0; do { sum += n % 10; } while(n /= 10); return sum; } unsigned a131382(unsigned n) { unsigned m; for (m = 1; n != digit_sum(m*n); m++); return m; } int main() { unsigned n; for (n = 1; n <= 70; n++) { prin...
IDENTIFICATION DIVISION. PROGRAM-ID. A131382. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 MAXIMUM PIC 99 VALUE 40. 03 N PIC 999. 03 M PIC 9(9). 03 N-TIMES-M PIC 9(9). 03 DIGITS P...
Can you help me rewrite this code in COBOL instead of C, keeping it the same logically?
#include <stdio.h> #include <complex.h> #include <math.h> #define FMTSPEC(arg) _Generic((arg), \ float: "%f", double: "%f", \ long double: "%Lf", unsigned int: "%u", \ unsigned long: "%lu", unsigned long long: "%llu", \ int: "%d", long: "%ld", long long: "%lld", \ default: "(invalid type (%p)") #...
IDENTIFICATION DIVISION. PROGRAM-ID. INTEGERNESS-PROGRAM. DATA DIVISION. WORKING-STORAGE SECTION. 01 INTEGERS-OR-ARE-THEY. 05 POSSIBLE-INTEGER PIC S9(9)V9(9). 05 DEFINITE-INTEGER PIC S9(9). 01 COMPLEX-NUMBER. 05 REAL-PART PIC S9(9)V9(9). 05 IMAGINARY-PART PIC S9(9)V9(9). PROCEDURE DIVISION. T...
Preserve the algorithm and functionality while converting the code from C to COBOL.
'--- added a flush to exit cleanly PRAGMA LDFLAGS `pkg-config --cflags --libs x11` PRAGMA INCLUDE <X11/Xlib.h> PRAGMA INCLUDE <X11/Xutil.h> OPTION PARSE FALSE '---XLIB is so ugly ALIAS XNextEvent TO EVENT ALIAS XOpenDisplay TO DISPLAY ALIAS DefaultScreen TO SCREEN ALIAS XCreateSimpleWindow TO CREATE ALIAS XCloseD...
identification division. program-id. x11-hello. installation. cobc -x x11-hello.cob -lX11 remarks. Use of private data is likely not cross platform. data division. working-storage section. 01 msg. 05 filler value z"S'up, Earth?". 01 msg-len ...
Port the following code from C to COBOL with equivalent syntax and logic.
#include <stdio.h> #include <stdlib.h> #include <math.h> int day(int y, int m, int d) { return 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730530; } void cycle(int diff, int l, char *t) { int p = round(100 * sin(2 * M_PI * diff / l)); printf("%12s cycle: %3i%%", t, p); if (abs(p) < 15) ...
identification division. program-id. bio. environment division. ************************************************************* **** To execute on command line enter program name followed **** by birth date ccyymmdd and then target date. **** Example: bio 180...
Produce a functionally identical COBOL code for the snippet given in C.
#include <stdio.h> #include <stdlib.h> #include <math.h> int day(int y, int m, int d) { return 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730530; } void cycle(int diff, int l, char *t) { int p = round(100 * sin(2 * M_PI * diff / l)); printf("%12s cycle: %3i%%", t, p); if (abs(p) < 15) ...
identification division. program-id. bio. environment division. ************************************************************* **** To execute on command line enter program name followed **** by birth date ccyymmdd and then target date. **** Example: bio 180...
Keep all operations the same but rewrite the snippet in COBOL.
#include <stdio.h> #define DEBUG_INT(x) printf( #x " at line %d\nresult: %d\n\n", __LINE__, x) int add(int x, int y) { int result = x + y; DEBUG_INT(x); DEBUG_INT(y); DEBUG_INT(result); DEBUG_INT(result+1); return result; } int main() { add(2, 7); return 0; }
gcobol identification division. program-id. steptrace. data division. working-storage section. procedure division. steptrace-main. display "explicit line" upon syserr >>Ddisplay "debug line" upon syserr display "from " FUNCTION...
Ensure the translated COBOL code behaves exactly like the original C snippet.
#include <stdbool.h> #include <stdio.h> int reverse(int n) { int result = 0; while (n > 0) { result = 10 * result + n % 10; n /= 10; } return result; } int main() { const int limit1 = 200; int row = 0; int num = 0; int n; for (n = 1; n < limit1; n++) { boo...
IDENTIFICATION DIVISION. PROGRAM-ID. SPECIAL-DIVISORS. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 02 CANDIDATE PIC 999. 02 CAND-REV PIC 999. 02 REVERSE PIC 999. 02 REV-DIGITS REDEFIN...
Preserve the algorithm and functionality while converting the code from C to COBOL.
#include <stdbool.h> #include <stdio.h> #include <string.h> #define MAX 100 void sieve(bool *prime, int max) { memset(prime, true, max+1); prime[0] = prime[1] = false; for (int p=2; p*p<=max; p++) for (int c=p*p; c<=max; c+=p) prime[c] = false; } int lo_fac(bool *prime, int n) {...
IDENTIFICATION DIVISION. PROGRAM-ID. MIN-MAX-PRIME-FACTOR-PRODUCT. DATA DIVISION. WORKING-STORAGE SECTION. 01 SIEVE-DATA. 03 FLAG-DATA PIC X(100) VALUE SPACES. 03 FLAGS REDEFINES FLAG-DATA, PIC X OCCURS 100 T...
Transform the following C# implementation into Factor, maintaining the same output and logic.
using System; using System.Numerics; namespace IntegerRoots { class Program { static BigInteger IRoot(BigInteger @base, int n) { if (@base < 0 || n <= 0) { throw new ArgumentException(); } int n1 = n - 1; BigInteger n2 = n; BigInt...
USING: io kernel locals math math.functions math.order prettyprint sequences ; :: (root) ( a b -- n ) a 1 - 1 :> ( a1 c [| x | a1 x * b x a1 ^ /i + a /i ] :> f c f call :> d d f call :> e [ c { d e } member? ] [ d c ] until d e min ; : root ( a b -- n ) dup 2 < [ nip ] [ (root) ] i...
Rewrite this program in Factor while keeping its functionality equivalent to the C# version.
using System; namespace LastSundayOfEachMonth { class Program { static void Main() { Console.Write("Year to calculate: "); string strYear = Console.ReadLine(); int year = Convert.ToInt32(strYear); DateTime date; for (int i = 1; i <= ...
USING: calendar calendar.format command-line io kernel math math.parser sequences ; IN: rosetta-code.last-sunday : parse-year ( -- ts ) (command-line) second string>number <year> ; : print-last-sun ( ts -- ) last-sunday-of-month (timestamp>ymd) nl ; : inc-month ( ts -- ts' ) 1 months time+ ; : process...
Please provide an equivalent version of this C# code in Factor.
using System; namespace LastSundayOfEachMonth { class Program { static void Main() { Console.Write("Year to calculate: "); string strYear = Console.ReadLine(); int year = Convert.ToInt32(strYear); DateTime date; for (int i = 1; i <= ...
USING: calendar calendar.format command-line io kernel math math.parser sequences ; IN: rosetta-code.last-sunday : parse-year ( -- ts ) (command-line) second string>number <year> ; : print-last-sun ( ts -- ) last-sunday-of-month (timestamp>ymd) nl ; : inc-month ( ts -- ts' ) 1 months time+ ; : process...
Translate the given C# code snippet into Factor without altering its behavior.
using System; using System.Collections.Generic; namespace RandomLatinSquares { using Matrix = List<List<int>>; static class Helper { private static readonly Random rng = new Random(); public static void Shuffle<T>(this IList<T> list) { int n = list.Count; while (n...
USING: arrays combinators.extras fry io kernel math.matrices prettyprint random sequences sets ; IN: rosetta-code.random-latin-squares : rand-permutation ( n -- seq ) <iota> >array randomize ; : ls? ( n -- ? ) [ all-unique? ] column-map t [ and ] reduce ; : (ls) ( n -- m ) dup '[ _ rand-permutation ] replicate ; : ls ...
Write the same code in Factor as shown below in C#.
using System; class Program { static bool ispr(uint n) { if ((n & 1) == 0 || n < 2) return n == 2; for (uint j = 3; j * j <= n; j += 2) if (n % j == 0) return false; return true; } static void Main(string[] args) { uint c = 0; int nc; var ps = new uint[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }; va...
USING: grouping grouping.extras math math.combinatorics math.functions math.primes math.ranges prettyprint sequences sequences.extras ; 9 1 [a,b] all-subsets [ reverse 0 [ 10^ * + ] reduce-index ] [ prime? ] map-filter 10 "" pad-groups 10 group simple-table.
Translate the given C# code snippet into Factor without altering its behavior.
using System; using System.Collections.Generic; using System.Linq; static class Module1 { static Random r = new Random(); static List<int> getThree(int n) { List<int> g3 = new List<int>(); for (int i = 0; i < 4; i++) g3.Add(r.Next(n) + 1); g3.Sort(); g3.RemoveAt(0); return g3; ...
USING: combinators.short-circuit dice formatting io kernel math math.statistics qw sequences ; IN: rosetta-code.rpg-attributes-generator CONSTANT: stat-names qw{ Str Dex Con Int Wis Cha } : attribute ( -- n ) 4 [ ROLL: 1d6 ] replicate 3 <iota> kth-largests sum ; : stats ( -- seq ) 6 [ attribute ] replicate ;...
Write the same code in Factor as shown below in C#.
using System; using System.Dynamic; using System.Collections.Generic; public class Program { public static void Main() { string varname = Console.ReadLine(); dynamic expando = new ExpandoObject(); var map = expando as IDictionary<string, object>; map.Add(varname, "Hello...
42 readln set
Generate an equivalent Factor version of this C# code.
using System; using static System.Console; using System.Collections; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int lmt = 1000, amt, c = 0, sr = (int)Math.Sqrt(lmt), lm2; var res = new List<int>(); var pr = PG.Primes(lmt / 3 + 5).ToArray(); lm2 = pr.O...
USING: combinators.short-circuit formatting grouping io kernel math.primes.factors math.ranges prettyprint sequences sets ; : sq-free-semiprime? ( n -- ? ) factors { [ length 2 = ] [ all-unique? ] } 1&& ; : odd-sfs-upto ( n -- seq ) 1 swap 2 <range> [ sq-free-semiprime? ] filter ; 999 odd-sfs-upto dup length...