WeixiangYan/CodeTransOcean huggingface dataset:
Task: Find prime numbers of the form n_n_n+2







Python: 

def isPrime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False        
    return True

if __name__ == '__main__':
    for n in range(1, 200):
        if isPrime(n**3+2):
            print(f'{n}\t{n**3+2}');



COBOL:        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).
          03 DIV-CHECK          PIC 9(4)V9(4).
          03 FILLER             REDEFINES DIV-CHECK.
             05 FILLER          PIC 9(4).
             05 FILLER          PIC 9(4).
                88 DIVISIBLE    VALUE ZERO.
          03 FILLER             REDEFINES N3PLUS2.
             05 FILLER          PIC 9(6).
             05 FILLER          PIC 9.
                88 EVEN         VALUE 0, 2, 4, 6, 8.
          03 PRIME-FLAG         PIC X.
             88 PRIME           VALUE '*'.
          
       01 FORMAT.
          03 FILLER             PIC X(4)  VALUE "N = ".
          03 N-OUT              PIC ZZ9.
          03 FILLER             PIC X(17) VALUE " => N ** 3 + 2 = ".
          03 N3PLUS2-OUT        PIC Z(6)9.
          
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM TRY-N VARYING N FROM 1 BY 1
           UNTIL N IS GREATER THAN 200.
           STOP RUN.
       
       TRY-N.
           COMPUTE N3PLUS2 = N ** 3 + 2.
           PERFORM CHECK-PRIME.
           IF PRIME,
               MOVE N TO N-OUT,
               MOVE N3PLUS2 TO N3PLUS2-OUT,
               DISPLAY FORMAT.
        
       CHECK-PRIME SECTION.
       BEGIN.
           MOVE SPACE TO PRIME-FLAG.
           IF N3PLUS2 IS LESS THAN 5, GO TO TRIVIAL.
           IF EVEN, GO TO CHECK-PRIME-DONE.
           DIVIDE N3PLUS2 BY 3 GIVING DIV-CHECK.
           IF DIVISIBLE, GO TO CHECK-PRIME-DONE.
           MOVE ZERO TO DIV-SQ.
           MOVE 5 TO DIVISOR. 
           MOVE '*' TO PRIME-FLAG.
           PERFORM CHECK-DIVISOR 
               UNTIL NOT PRIME OR DIV-SQ IS GREATER THAN N3PLUS2.
           GO TO CHECK-PRIME-DONE.
       
       CHECK-DIVISOR.
           MULTIPLY DIVISOR BY DIVISOR GIVING DIV-SQ.
           DIVIDE N3PLUS2 BY DIVISOR GIVING DIV-CHECK.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 2 TO DIVISOR.
           DIVIDE N3PLUS2 BY DIVISOR GIVING DIV-CHECK.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 4 TO DIVISOR.
           
       TRIVIAL.
           IF N3PLUS2 IS EQUAL TO 2 OR EQUAL TO 3,
               MOVE '*' TO PRIME-FLAG.
       
       CHECK-PRIME-DONE.
           EXIT.
Task: ABC words

C: #include <stdio.h>
#include <string.h>

int match(const char *word) {
    const char *a = strchr(word, 'a');
    const char *b = strchr(word, 'b');
    const char *c = strchr(word, 'c');
    return a && b && c && a<b && b<c;
}

int main() {
    char word[80];
    FILE *file = fopen("unixdict.txt", "r");
    if (!file) {
        fprintf(stderr, "Cannot open unixdict.txt");
        return -1;
    }
    
    while (!feof(file)) {
        fgets(word, sizeof(word), file);
        if(match(word)) printf("%s", word);
    }
    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(32).
       
       WORKING-STORAGE SECTION.
       01 A               PIC 99.
       01 B               PIC 99.
       01 C               PIC 99.
       01 X               PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO A, B, C, X.
           INSPECT WORD TALLYING A FOR CHARACTERS BEFORE INITIAL 'a'.
           INSPECT WORD TALLYING B FOR CHARACTERS BEFORE INITIAL 'b'.
           INSPECT WORD TALLYING C FOR CHARACTERS BEFORE INITIAL 'c'.
           INSPECT WORD TALLYING X FOR CHARACTERS BEFORE INITIAL ' '.
           IF A IS LESS THAN B 
           AND B IS LESS THAN C 
           AND C IS LESS THAN X,
               DISPLAY WORD.
Task: Two identical strings

C: #include <stdio.h>
#include <stdint.h>

uint8_t bit_length(uint32_t n) {
    uint8_t r;
    for (r=0; n; r++) n >>= 1;
    return r;
}

uint32_t concat_bits(uint32_t n) {
    return (n << bit_length(n)) | n;
}

char *bits(uint32_t n) {
    static char buf[33];
    char *ptr = &buf[33];
    *--ptr = 0;
    do {
        *--ptr = '0' + (n & 1);
    } while (n >>= 1);
    return ptr;
}

int main() {
    uint32_t n, r;
    for (n=1; (r = concat_bits(n)) < 1000; n++) {
        printf("%d: %s\n", r, bits(r));
    }
    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  IDENTICAL-STRINGS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 INPUT-NUMBER            PIC 9(4).
          03 BINARY-REPRESENTATION   PIC 9(10).
          03 BIT                     REDEFINES BINARY-REPRESENTATION,
                                     PIC 9 OCCURS 10 TIMES.
          03 FIRST-SET-BIT           PIC 99.
          03 CURRENT-BIT             PIC 99.
          03 SECOND-BIT              PIC 99.
          03 BIT-VALUE               PIC 9(4).
          03 OUTPUT-NUMBER           PIC 9(4) VALUE ZERO.
          03 REMAINING-BITS          PIC 9(4)V9.
          03 FILLER                  REDEFINES REMAINING-BITS.
             05 REST                 PIC 9(4).
             05 FILLER               PIC 9.
                88 BIT-IS-SET        VALUE 5.

       01 OUTPUT-FORMAT.
          03 DECIMAL-OUTPUT          PIC Z(3)9.
          03 BINARY-OUTPUT           PIC Z(9)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM IDENTICAL-STRING
               VARYING INPUT-NUMBER FROM 1 BY 1
               UNTIL OUTPUT-NUMBER IS GREATER THAN 1000.
           STOP RUN.

       IDENTICAL-STRING.
           MOVE ZERO TO BINARY-REPRESENTATION.
           MOVE 10 TO CURRENT-BIT.
           MOVE INPUT-NUMBER TO REMAINING-BITS.
           PERFORM EXTRACT-BIT UNTIL REMAINING-BITS EQUAL ZERO.
           MOVE CURRENT-BIT TO FIRST-SET-BIT.
           MOVE 10 TO SECOND-BIT.
           PERFORM COPY-BIT UNTIL SECOND-BIT IS EQUAL TO FIRST-SET-BIT.
           MOVE ZERO TO OUTPUT-NUMBER.
           IF CURRENT-BIT IS EQUAL TO ZERO, MOVE 1 TO CURRENT-BIT.
           PERFORM INSERT-BIT
               VARYING CURRENT-BIT FROM CURRENT-BIT BY 1
               UNTIL CURRENT-BIT IS GREATER THAN 10.
           MOVE OUTPUT-NUMBER TO DECIMAL-OUTPUT.
           MOVE BINARY-REPRESENTATION TO BINARY-OUTPUT.
           IF OUTPUT-NUMBER IS LESS THAN 1000,
               DISPLAY DECIMAL-OUTPUT ": " BINARY-OUTPUT.

       EXTRACT-BIT.
           DIVIDE 2 INTO REMAINING-BITS.
           IF BIT-IS-SET, MOVE 1 TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM CURRENT-BIT.
           MOVE REST TO REMAINING-BITS.

       COPY-BIT.
           MOVE BIT(SECOND-BIT) TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM SECOND-BIT.
           SUBTRACT 1 FROM CURRENT-BIT.

       INSERT-BIT.
           COMPUTE BIT-VALUE = 2 ** (10 - CURRENT-BIT)
           MULTIPLY BIT(CURRENT-BIT) BY BIT-VALUE.
           ADD BIT-VALUE TO OUTPUT-NUMBER.
Task: Sum of first n cubes

C: #include <stdio.h>

int main() {
    for (int i = 0, sum = 0; i < 50; ++i) {
        sum += i * i * i;
        printf("%7d%c", sum, (i + 1) % 5 == 0 ? '\n' : ' ');
    }
    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 STEP         PIC 99.
          03 CUBE         PIC 9(7).
          03 CUBE-SUM     PIC 9(7) VALUE 0.
 
       01 OUTPUT-FORMAT.
          03 OUT-LINE     PIC X(40) VALUE SPACES.
          03 OUT-PTR      PIC 99 VALUE 1.
          03 OUT-NUM      PIC Z(7)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM ADD-CUBE VARYING STEP FROM 0 BY 1
               UNTIL STEP IS EQUAL TO 50.
           STOP RUN.

       ADD-CUBE.
           COMPUTE CUBE = STEP ** 3.
           ADD CUBE TO CUBE-SUM.
           MOVE CUBE-SUM TO OUT-NUM.
           STRING OUT-NUM DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 41,
               DISPLAY OUT-LINE,
               MOVE 1 TO OUT-PTR.
Task: Count how many vowels and consonants occur in a string

C: 

#include <stdio.h>

char vowels[] = {'a','e','i','o','u','\n'};

int len(char * str) {
	int i = 0;
	while (str[i] != '\n') i++;
	return i;
}

int  isvowel(char c){
	int b = 0;
	int v = len(vowels);
	for(int i = 0; i < v;i++) {
		if(c == vowels[i]) {
			b = 1;
			break; 
		}
	}
	return b;
}

int isletter(char c){
	return ((c >= 'a') && (c <= 'z') || (c >= 'A') && (c <= 'Z'));
}

int isconsonant(char c){
	return isletter(c) && !isvowel(c);
}

int cVowels(char * str) {
	int i = 0;
	int count = 0;
	while (str[i] != '\n') {
		if (isvowel(str[i])) {
			count++;;
		}
		i++;
	}
	return count;
}

int cConsonants(char * str ) {
	int i = 0;
	int count = 0;
	while (str[i] != '\n') {
		if (isconsonant(str[i])) {
			count++;
		}
		i++;
	}
	return count;
}

int main() {

	char buff[] = "This is 1 string\n";
	printf("%4d, %4d, %4d, %s\n", cVowels(buff), cConsonants(buff), len(buff), buff);

	char buff2[] = "This is a second string\n";
	printf("%4d, %4d, %4d, %s\n", cVowels(buff2), cConsonants(buff2), len(buff2),  buff2);


	printf("a: %d\n", isvowel('a'));
	printf("b: %d\n", isvowel('b'));
	printf("Z: %d\n", isconsonant('Z'));
	printf("1: %d\n", isletter('1'));
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. VOWELS-AND-CONSONANTS.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONSTANTS.
          03 LETTERS-DAT.
             05 FILLER      PIC X(5) VALUE "AEIOU".
             05 FILLER      PIC X(5) VALUE "aeiou".
             05 FILLER      PIC X(21) VALUE "BCDFGHJKLMNPQRSTVWXYZ".
             05 FILLER      PIC X(21) VALUE "bcdfghjklmnpqrstvwxyz".
          03 LETTERS        REDEFINES LETTERS-DAT.
             05 VOWELS      PIC X OCCURS 10 TIMES INDEXED BY V.
             05 CONSONANTS  PIC X OCCURS 42 TIMES INDEXED BY C.
      
       01 VARIABLES.
          03 IN-STR         PIC X(80).
          03 N-VOWELS       PIC 99.
          03 N-CONSONANTS   PIC 99.
      
       01 REPORT.
          03 R-VOWELS       PIC Z9.
          03 FILLER         PIC X(9) VALUE " vowels, ".
          03 R-CONSONANTS   PIC Z9.
          03 FILLER         PIC X(12) VALUE " consonants.".
         
       PROCEDURE DIVISION.
       BEGIN.
           MOVE "If not now, then when? If not us, then who?"
           TO IN-STR.
           PERFORM COUNT-AND-SHOW.
           STOP RUN.
          
       COUNT-AND-SHOW.
           DISPLAY IN-STR.
           PERFORM COUNT-VOWELS-AND-CONSONANTS.
           MOVE N-VOWELS TO R-VOWELS.
           MOVE N-CONSONANTS TO R-CONSONANTS.
           DISPLAY REPORT.
       
       COUNT-VOWELS-AND-CONSONANTS.
           MOVE ZERO TO N-VOWELS, N-CONSONANTS.
           SET V TO 1.
           PERFORM COUNT-VOWEL 10 TIMES.
           SET C TO 1.
           PERFORM COUNT-CONSONANT 42 TIMES.
        
       COUNT-VOWEL.
           INSPECT IN-STR TALLYING N-VOWELS FOR ALL VOWELS(V).
           SET V UP BY 1.
       
       COUNT-CONSONANT.
           INSPECT IN-STR TALLYING N-CONSONANTS FOR ALL CONSONANTS(C).
           SET C UP BY 1.
Task: Call a foreign-language function

C: 



#include <stdio.h>

void sayHello(char* name){
    printf("Hello %s!\n", name);
}

int doubleNum(int num){
    return num * 2;
}









COBOL:        identification division.
       program-id. foreign.

       data division.
       working-storage section.
       01 hello.
          05 value z"Hello, world".
       01 duplicate    usage pointer.
       01 buffer       pic x(16) based.
       01 storage      pic x(16).

       procedure division.
       call "strdup" using hello returning duplicate
           on exception
               display "error calling strdup" upon syserr
       end-call
       if duplicate equal null then
           display "strdup returned null" upon syserr
       else
           set address of buffer to duplicate
           string buffer delimited by low-value into storage
           display function trim(storage)
           call "free" using by value duplicate
               on exception
                   display "error calling free" upon syserr
       end-if
       goback.
Task: Disarium numbers

C: #include <stdio.h>
#include <stdlib.h>
#include <math.h>

int power (int base, int exponent) {
    int result = 1;
    for (int i = 1; i <= exponent; i++) {
        result *= base;
    }
    return result;
}

int is_disarium (int num) {
    int n = num;
    int sum = 0;
    int len = n <= 9 ? 1 : floor(log10(n)) + 1;
    while (n > 0) {
        sum += power(n % 10, len);
        n /= 10;
        len--;
    }

    return num == sum;
}

int main() {
    int count = 0;
    int i = 0;
    while (count < 19) {
        if (is_disarium(i)) {
            printf("%d ", i);
            count++;
        }
        i++;
    }
    printf("%s\n", "\n");
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. DISARIUM.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE     PIC 9(9).
          03 DIGITS        PIC 9 OCCURS 9 TIMES, REDEFINES CANDIDATE.
          03 IDX           PIC 99.
          03 EXPONENT      PIC 99.
          03 DGT-POWER     PIC 9(9).
          03 DGT-POWER-SUM PIC 9(9).
          03 CAND-OUT      PIC Z(8)9.
          03 AMOUNT        PIC 99 VALUE 18.
          
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM DISARIUM-TEST VARYING CANDIDATE FROM ZERO BY 1
           UNTIL AMOUNT IS ZERO.
           STOP RUN.
        
       DISARIUM-TEST.
           MOVE ZERO TO DGT-POWER-SUM.
           MOVE 1 TO EXPONENT, IDX.
           INSPECT CANDIDATE TALLYING IDX FOR LEADING ZEROES.
           PERFORM ADD-DIGIT-POWER UNTIL IDX IS GREATER THAN 9.
           IF DGT-POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO CAND-OUT,
               DISPLAY CAND-OUT,
               SUBTRACT 1 FROM AMOUNT.
           
       ADD-DIGIT-POWER.
           COMPUTE DGT-POWER = DIGITS(IDX) ** EXPONENT.
           ADD DGT-POWER TO DGT-POWER-SUM.
           ADD 1 TO EXPONENT.
           ADD 1 TO IDX.
Task: Cousin primes

C: #include <stdio.h>
#include <string.h>

#define LIMIT 1000

void sieve(int max, char *s) {
    int p, k;
    memset(s, 0, max);
    for (p=2; p*p<=max; p++)
        if (!s[p]) 
            for (k=p*p; k<=max; k+=p) 
                s[k]=1;
}

int main(void) {
    char primes[LIMIT+1];
    int p, count=0;
    
    sieve(LIMIT, primes);
    for (p=2; p<=LIMIT; p++) {
        if (!primes[p] && !primes[p+4]) {
            count++;
            printf("%4d: %4d\n", p, p+4);
        }
    }
    
    printf("There are %d cousin prime pairs below %d.\n", count, LIMIT);
    return 0;
}









COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. COUSIN-PRIMES.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 PRIME-SIEVE.
           02 PRIME-FLAG        PIC 9 OCCURS 1000 INDEXED BY P, Q.
              88 PRIME          VALUE 1.
           02 STEP-SIZE         PIC 999.
           02 X                 PIC 999.
           02 P-START           PIC 999.
           02 AMOUNT            PIC 999 VALUE 0.
        01 OUTPUT-FORMAT.
           02 COUSIN1           PIC ZZ9.
           02 COUSIN2           PIC ZZ9.
           
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM SIEVE.
            PERFORM TEST-COUSINS VARYING P FROM 2 BY 1
                UNTIL P IS GREATER THAN 996.
            MOVE AMOUNT TO COUSIN1.
            DISPLAY COUSIN1 ' pairs found.'
            STOP RUN.
        
        TEST-COUSINS.
            IF PRIME(P) AND PRIME(P + 4)
                SET X TO P 
                MOVE X TO COUSIN1
                ADD X, 4 GIVING COUSIN2
                DISPLAY COUSIN1 ' ' COUSIN2
                ADD 1 TO AMOUNT.
        
        SIEVE SECTION.
        BEGIN.
            PERFORM FLAG-PRIME VARYING Q FROM 1 BY 1
                UNTIL Q IS GREATER THAN 1000.
            PERFORM SIEVE-PRIME VARYING P FROM 2 BY 1
                UNTIL P IS GREATER THAN 32.
            GO TO DONE.
        
        SIEVE-PRIME.
            IF PRIME(P)
                SET X TO P
                COMPUTE P-START = X ** 2
                PERFORM UNFLAG-PRIME VARYING Q FROM P-START BY X
                    UNTIL Q IS GREATER THAN 1000.
                    
        FLAG-PRIME.   MOVE 1 TO PRIME-FLAG(Q).
        UNFLAG-PRIME. MOVE 0 TO PRIME-FLAG(Q).
        DONE. EXIT.
Task: Flow-control structures

C: int main()
{
  int i,j;
  for (j=1; j<1000; j++) {
    for (i=0; i<j, i++) {
      if (exit_early())
        goto out;
      
    }
  }
out:
  return 0;
}









COBOL:        PROGRAM-ID. Go-To-Example.

       PROCEDURE DIVISION.
       Foo.
           DISPLAY "Just a reminder: GO TOs are evil."

           GO TO Foo
           .
Task: Return multiple values

C: #include<stdio.h>

typedef struct{
	int integer;
	float decimal;
	char letter;
	char string[100];
	double bigDecimal;
}Composite;

Composite example()
{
	Composite C = {1, 2.3, 'a', "Hello World", 45.678};
	return C;
}


int main()
{
	Composite C = example();

	printf("Values from a function returning a structure : { %d, %f, %c, %s, %f}\n", C.integer, C.decimal, C.letter, C.string, C.bigDecimal);

	return 0;
}









COBOL:        identification division.
       program-id. multiple-values.

       environment division.
       configuration section.
       repository.
           function multiples
           function all intrinsic.

       REPLACE ==:linked-items:== BY ==
       01 a usage binary-long.
       01 b pic x(10).
       01 c usage float-short.
       ==
       ==:record-item:== BY ==
       01 master.
          05 ma usage binary-long.
          05 mb pic x(10).
          05 mc usage float-short.
       ==.

       data division.
       working-storage section.
       :linked-items:

       :record-item:
       
       procedure division.
       sample-main.

       move 41 to a
       move "aaaaabbbbb" to b
       move function e to c

       display "Original: " a ", " b ", " c
       call "subprogram" using a b c
       display "Modified: " a ", " b ", " c
       
       move multiples() to master
       display "Multiple: " ma ", " mb ", " mc

       goback.
       end program multiple-values.

      
       identification division.
       program-id. subprogram.

       data division.
       linkage section.
       :linked-items:

       procedure division using a b c.
       add 1 to a
       inspect b converting "a" to "b"
       divide 2 into c
       goback.
       end program subprogram.

      
       identification division.
       function-id. multiples.

       data division.
       linkage section.
       :record-item:

       procedure division returning master.
       move 84 to ma
       move "multiple" to mb
       move function pi to mc
       goback.
       end function multiples.
Task: Substring_Top and tail

C: #include <string.h>
#include <stdlib.h>
#include <stdio.h>

int main( int argc, char ** argv ){
  const char * str_a = "knight";
  const char * str_b = "socks";
  const char * str_c = "brooms";

  char * new_a = malloc( strlen( str_a ) - 1 );
  char * new_b = malloc( strlen( str_b ) - 1 );
  char * new_c = malloc( strlen( str_c ) - 2 );

  strcpy( new_a, str_a + 1 );
  strncpy( new_b, str_b, strlen( str_b ) - 1 );
  strncpy( new_c, str_c + 1, strlen( str_c ) - 2 );

  printf( "%s\n%s\n%s\n", new_a, new_b, new_c );

  free( new_a );
  free( new_b );
  free( new_c );

  return 0;
}









COBOL:        identification division.
       program-id. toptail.

       data division.
       working-storage section.
       01 data-field.
          05 value "[this is a test]".

       procedure division.
       sample-main.
       display data-field
      
       display data-field(2:)
       display data-field(1:length of data-field - 1)
       display data-field(2:length of data-field - 2)
       goback.
       end program toptail.
Task: Boolean values

C: int a = 0;
int b = 1;
int c;
string str1 = "initialized string";
string str2; 

if (a) {puts("first test a is false");}         
if (b) {puts("second test b is true");}         
if (c) {puts("third test b is false");}         
if (!defined(c)) {puts("fourth test is true");} 
if (str1) {puts("fifth test str1 is true");}    
if (str2) {puts("sixth test str2 is false");}   









COBOL:        01  some-bool               PIC 1 BIT.
Task: First 9 prime Fibonacci number

C: #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

bool isPrime(uint64_t n) {
    if (n < 2) return false;
    if (!(n%2)) return n == 2;
    if (!(n%3)) return n == 3;
    uint64_t d = 5;
    while (d*d <= n) {
        if (!(n%d)) return false;
        d += 2;
        if (!(n%d)) return false;
        d += 4;
    }
    return true;
}

int main() {
    uint64_t f1 = 1, f2 = 1, f3;
    int count = 0, limit = 12; 
    printf("The first %d prime Fibonacci numbers are:\n", limit);
    while (count < limit) {
        f3 = f1 + f2;
        if (isPrime(f3)) {
            printf("%ld ", f3);
            count++;
        }
        f1 = f2;
        f2 = f3;
    }
    printf("\n");
    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. PRIME-FIBONACCI.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 FIBONACCI-VARS.
          03 FIB                PIC 9(6).
          03 FIB-B              PIC 9(6).
          03 FIB-C              PIC 9(6).
          03 FIB-OUT            PIC Z(5)9.
       01 PRIME-VARS.   
          03 PRIME-FLAG         PIC X.
             88 PRIME           VALUE 'X'.
          03 DSOR               PIC 9(4).
          03 DSOR-SQ            PIC 9(6).
          03 DIV-RSLT           PIC 9(6)V9(3).
          03 FILLER             REDEFINES DIV-RSLT.
             05 FILLER          PIC 9(6).
             05 FILLER          PIC 9(3).
                88 DIVISIBLE    VALUE ZERO.
          
       PROCEDURE DIVISION.
       BEGIN.
           MOVE 1 TO FIB, FIB-B.
           PERFORM FIND-PRIME-FIBONACCI 9 TIMES.
           STOP RUN.
       
       FIND-PRIME-FIBONACCI.
           ADD FIB, FIB-B GIVING FIB-C.
           MOVE FIB-B TO FIB.
           MOVE FIB-C TO FIB-B.
           PERFORM CHECK-PRIME.
           IF NOT PRIME, GO TO FIND-PRIME-FIBONACCI.
           MOVE FIB TO FIB-OUT.
           DISPLAY FIB-OUT.
       
       CHECK-PRIME SECTION.
       BEGIN.
           MOVE SPACE TO PRIME-FLAG.
           IF FIB IS LESS THAN 5, GO TO TRIVIAL-PRIME.
           DIVIDE FIB BY 2 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           DIVIDE FIB BY 3 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           MOVE 5 TO DSOR.
           MOVE 25 TO DSOR-SQ.
           MOVE 'X' TO PRIME-FLAG.
           PERFORM TEST-DIVISOR 
           UNTIL NOT PRIME OR DSOR-SQ IS GREATER THAN FIB.
           GO TO DONE.
           
       TEST-DIVISOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 2 TO DSOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 4 TO DSOR.
           MULTIPLY DSOR BY DSOR GIVING DSOR-SQ.
       
       TRIVIAL-PRIME.
           IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
       DONE.
           EXIT.