WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sorting algorithms_Stooge sort

C: #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);
   }
}
  
int main(int argc, char *argv[])
{
   int nums[] = {1, 4, 5, 3, -6, 3, 7, 10, -2, -5, 7, 5, 9, -3, 7};
   int i, n;
  
   n = sizeof(nums)/sizeof(int);
   StoogeSort(nums, 0, n-1);
   
   for(i = 0; i <= n-1; i++)
      printf("%5d", nums[i]);
   
   return 0;
}










Fortran: program Stooge
  implicit none

  integer :: i
  integer :: array(50) = (/ (i, i = 50, 1, -1) /) 
  
  call Stoogesort(array)
  write(*,"(10i5)") array

contains

recursive subroutine Stoogesort(a)
  integer, intent(in out) :: a(:)
  integer :: j, t, temp
 
   j = size(a)
   if(a(j) < a(1)) then
     temp = a(j)
     a(j) = a(1)
     a(1) = temp
   end if

  if(j > 2) then
    t = j / 3
    call Stoogesort(a(1:j-t))
    call Stoogesort(a(1+t:j))
    call Stoogesort(a(1:j-t)) 
  end if

end subroutine
end program
Task: Truncate a file

C: #include <windows.h>
#include <stdio.h>
#include <wchar.h>


void
oops(const wchar_t *message)
{
	wchar_t *buf;
	DWORD error;

	buf = NULL;
	error = GetLastError();
	FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
	    FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
	    NULL, error, 0, (wchar_t *)&buf, 0, NULL);

	if (buf) {
		fwprintf(stderr, L"%ls: %ls", message, buf);
		LocalFree(buf);
	} else {
		
		fwprintf(stderr, L"%ls: unknown error 0x%x\n",
		    message, error);
	}
}

int
dotruncate(wchar_t *fn, LARGE_INTEGER fp)
{
	HANDLE fh;

	fh = CreateFileW(fn, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		oops(fn);
		return 1;
	}

	if (SetFilePointerEx(fh, fp, NULL, FILE_BEGIN) == 0 ||
	    SetEndOfFile(fh) == 0) {
		oops(fn);
		CloseHandle(fh);
		return 1;
	}

	CloseHandle(fh);
	return 0;
}


int
main()
{
	LARGE_INTEGER fp;
	int argc;
	wchar_t **argv, *fn, junk[2];

	
	argv = CommandLineToArgvW(GetCommandLineW(), &argc);
	if (argv == NULL) {
		oops(L"CommandLineToArgvW");
		return 1;
	}

	if (argc != 3) {
		fwprintf(stderr, L"usage: %ls filename length\n", argv[0]);
		return 1;
	}

	fn = argv[1];

	
	if (swscanf(argv[2], L"%lld%1ls", &fp.QuadPart, &junk) != 1) {
		fwprintf(stderr, L"%ls: not a number\n", argv[2]);
		return 1;
	}

	return dotruncate(fn, fp);
}










Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,NB)
       CHARACTER*(*) FNAME	
       INTEGER NB		
       INTEGER L		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST		
       CHARACTER*1 B		
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (NB.LE.0)     CALL CROAK("Chop must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READWRITE",	
     1   FORM="UNFORMATTED",RECL=1,ACCESS="DIRECT")		
        OPEN (T,STATUS="SCRATCH",FORM="UNFORMATTED",RECL=1)	

Copy the desired "records" to the temporary file.
   10   DO L = 1,NB	
          READ  (F,REC = L,ERR = 20) B	
          WRITE (T) B			
        END DO		
   20   IF (L.LE.NB) CALL CROAK("Short file
Convert from input to output...
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
        DO L = 1,NB	
          READ  (T) B		
          WRITE (F,"(A1,$)") B	
        END DO		
Completed.
   30   CLOSE(T)	
        CLOSE(F)	
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",12)
      END
Task: Sorting algorithms_Shell sort

C: #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, char **av) {
    int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
    int n = sizeof a / sizeof a[0];
    int i;
    for (i = 0; i < n; i++)
        printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
    shell_sort(a, n);
    for (i = 0; i < n; i++)
        printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
    return 0;
}










Fortran: MODULE sort

CONTAINS

SUBROUTINE Shell_Sort(a)

  IMPLICIT NONE
  INTEGER :: i, j, increment
  REAL :: temp
  REAL, INTENT(in out) :: a(:)
	
  increment = SIZE(a) / 2
  DO WHILE (increment > 0)
      DO i = increment+1, SIZE(a)
         j = i
         temp = a(i)
         DO WHILE (j >= increment+1 .AND. a(j-increment) > temp)
            a(j) = a(j-increment)
            j = j - increment
         END DO
         a(j) = temp
      END DO
      IF (increment == 2) THEN
   	  increment = 1
      ELSE
         increment = increment * 5 / 11
      END IF      
  END DO
 
END SUBROUTINE Shell_Sort

END MODULE sort

PROGRAM Shellsort

USE sort

  IMPLICIT NONE
  REAL :: array(1000)
     
  CALL RANDOM_SEED
  CALL RANDOM_NUMBER(array)
 
  WRITE (*,*) "Unsorted array"
  WRITE (*,*) array
  WRITE (*,*) 
  CALL Shell_Sort(array)
  WRITE (*,*) "Sorted array"
  WRITE (*,*) array
  
END PROGRAM Shellsort
Task: Inverted syntax

C: #include <stdio.h>
#include <stdlib.h>
#define otherwise       do { register int _o = 2; do { switch (_o) {  case 1:
#define given(Mc)       ;case 0: break; case 2: _o = !!(Mc); continue; } break; } while (1); } while (0)


int foo() { return 1; }

main()
{
        int a = 0;

        otherwise  a = 4 given (foo());
        printf("%d\n", a);
        exit(0);
}










Fortran:       INQUIRE(FILE = FILENAME(1:L), EXIST = MAYBE, ERR = 666, IOSTAT = RESULT)
Task: Numeric error propagation

C: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
 
typedef struct{
    double value;
    double delta;
}imprecise;
 
#define SQR(x) ((x) * (x))
imprecise imprecise_add(imprecise a, imprecise b)
{
    imprecise ret;
    ret.value = a.value + b.value;
    ret.delta = sqrt(SQR(a.delta) + SQR(b.delta));
    return ret;
}
 
imprecise imprecise_mul(imprecise a, imprecise b)
{
    imprecise ret;
    ret.value = a.value * b.value;
    ret.delta = sqrt(SQR(a.value * b.delta) + SQR(b.value * a.delta));
    return ret;
}
 
imprecise imprecise_div(imprecise a, imprecise b)
{
    imprecise ret;
    ret.value = a.value / b.value;
    ret.delta = sqrt(SQR(a.value * b.delta) + SQR(b.value * a.delta)) / SQR(b.value);
    return ret;
}
 
imprecise imprecise_pow(imprecise a, double c)
{
    imprecise ret;
    ret.value = pow(a.value, c);
    ret.delta = fabs(ret.value * c * a.delta / a.value);
    return ret;
}

char* printImprecise(imprecise val)
{
	char principal[30],error[30],*string,sign[2];
	sign[0] = 241;    
	sign[1] = 00;
	
	sprintf(principal,"%f",val.value);
	sprintf(error,"%f",val.delta);
	
	string = (char*)malloc((strlen(principal)+1+strlen(error)+1)*sizeof(char));
	
	strcpy(string,principal);
	strcat(string,sign);
	strcat(string,error);
	
	return string;
}
 
int main(void) {
    imprecise x1 = {100, 1.1};
    imprecise y1 = {50, 1.2};
    imprecise x2 = {-200, 2.2};
    imprecise y2 = {-100, 2.3};
    imprecise d;
 
    d = imprecise_pow(imprecise_add(imprecise_pow(imprecise_add(x1, x2), 2),imprecise_pow(imprecise_add(y1, y2), 2)), 0.5);
    printf("Distance, d, between the following points :");
    printf("\n( x1, y1) = ( %s, %s)",printImprecise(x1),printImprecise(y1));
    printf("\n( x2, y2) = ( %s, %s)",printImprecise(x2),printImprecise(y2));
    printf("\nis d = %s", printImprecise(d));
    return 0;
}










Fortran:       PROGRAM CALCULATE	
      REAL X1, Y1, X2, Y2	
      REAL X1E,Y1E,X2E,Y2E	
      DATA X1, Y1 ,X2, Y2 /100., 50., 200.,100./	
      DATA X1E,Y1E,X2E,Y2E/  1.1, 1.2,  2.2, 2.3/	
      REAL DX,DY,D2,D,DXE,DYE,E	
      CHARACTER*1 C			
      PARAMETER (C = CHAR(241))		
      REAL SD	
      SD(X,P,S) = P*ABS(X)**(P - 1)*S	
      WRITE (6,1) X1,C,X1E,Y1,C,Y1E,	
     1            X2,C,X2E,Y2,C,Y2E	
    1 FORMAT ("Euclidean distance between two points:"/	
     1 ("(",F5.1,A1,F3.1,",",F5.1,A1,F3.1,")"))		
      DX = (X1 - X2)			
      DXE = SQRT(X1E**2 + X2E**2)	
      DY = (Y1 - Y2)			
      DYE = SQRT(Y1E**2 + Y2E**2)	
      D2 = DX**2 + DY**2		
      DXE = SD(DX,2,DXE)		
      DYE = SD(DY,2,DYE)		
      E = SQRT(DXE**2 + DYE**2)		
      D = SQRT(D2)			
      E = SD(D2,0.5,E)			
      WRITE (6,2) D,C,E			
    2 FORMAT ("Distance",F6.1,A1,F4.2)	
      END
Task: Trabb Pardo–Knuth algorithm

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

int
main ()
{
  double inputs[11], check = 400, result;
  int i;

  printf ("\nPlease enter 11 numbers :");

  for (i = 0; i < 11; i++)
    {
      scanf ("%lf", &inputs[i]);
    }

  printf ("\n\n\nEvaluating f(x) = |x|^0.5 + 5x^3 for the given inputs :");

  for (i = 10; i >= 0; i--)
    {
      result = sqrt (fabs (inputs[i])) + 5 * pow (inputs[i], 3);

      printf ("\nf(%lf) = ");

      if (result > check)
        {
          printf ("Overflow!");
        }

      else
        {
          printf ("%lf", result);
        }
    }

  return 0;
}










Fortran: program tpk
  implicit none
  
  real, parameter :: overflow = 400.0
  real :: a(11), res
  integer :: i
 
  write(*,*) "Input eleven numbers:"
  read(*,*) a
 
  a = a(11:1:-1)
  do i = 1, 11
    res = f(a(i))
    write(*, "(a, f0.3, a)", advance = "no") "f(", a(i), ") = "
    if(res > overflow) then
      write(*, "(a)") "overflow
    else
       write(*, "(f0.3)") res
    end if
  end do  
      
contains

real function f(x)
  real, intent(in) :: x
  
  f = sqrt(abs(x)) + 5.0*x**3

end function  
end program
Task: Rate counter

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



struct rate_state_s
{
    time_t lastFlush;
    time_t period;
    size_t tickCount;
};

void tic_rate(struct rate_state_s* pRate)
{
    pRate->tickCount += 1;

    time_t now = time(NULL);

    if((now - pRate->lastFlush) >= pRate->period)
    {
        
        size_t tps = 0.0;
        if(pRate->tickCount > 0)
            tps = pRate->tickCount / (now - pRate->lastFlush);

        printf("%u tics per second.\n", tps);

        
        pRate->tickCount = 0;
        pRate->lastFlush = now;
    }
}



void something_we_do()
{
    
    
    
    
    
    
    
    volatile size_t anchor = 0;
    size_t x = 0;
    for(x = 0; x < 0xffff; ++x)
    {
        anchor = x;
    }
}

int main()
{
    time_t start = time(NULL);

    struct rate_state_s rateWatch;
    rateWatch.lastFlush = start;
    rateWatch.tickCount = 0;
    rateWatch.period = 5; 

    time_t latest = start;
    
    for(latest = start; (latest - start) < 20; latest = time(NULL))
    {
        
        something_we_do();

        
        tic_rate(&rateWatch);
    }

    return 0;
}










Fortran:       DO I = FIRST,LAST
        IF (PROGRESSNOTE((I - FIRST)/(LAST - FIRST + 1.0))) WRITE (6,*) "Reached ",I,", towards ",LAST
        ...much computation...
      END DO
Task: Topswops

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

typedef struct { char v[16]; } deck;
typedef unsigned int uint;

uint n, d, best[16];

void tryswaps(deck *a, uint f, uint s) {
#	define A a->v
#	define B b.v
	if (d > best[n]) best[n] = d;
	while (1) {
		if ((A[s] == s || (A[s] == -1 && !(f & 1U << s)))
			&& (d + best[s] >= best[n] || A[s] == -1))
			break;

		if (d + best[s] <= best[n]) return;
		if (!--s) return;
	}

	d++;
	deck b = *a;
	for (uint i = 1, k = 2; i <= s; k <<= 1, i++) {
		if (A[i] != i && (A[i] != -1 || (f & k)))
			continue;

		for (uint j = B[0] = i; j--;) B[i - j] = A[j];
		tryswaps(&b, f | k, s);
	}
	d--;
}

int main(void) {
	deck x;
	memset(&x, -1, sizeof(x));
	x.v[0] = 0;

	for (n = 1; n < 13; n++) {
		tryswaps(&x, 1, n - 1);
		printf("%2d: %d\n", n, best[n]);
	}

	return 0;
}










Fortran: module top
implicit none
contains 
recursive function f(x) result(m)
  integer :: n, m, x(:),y(size(x)), fst
  fst = x(1)
  if (fst == 1) then
    m = 0
  else
    y(1:fst) = x(fst:1:-1)
    y(fst+1:) = x(fst+1:)
    m = 1 + f(y)
  end if
end function

recursive function perms(x) result(p)
integer, pointer     :: p(:,:), q(:,:)
integer              :: x(:), n, k, i
n = size(x)
if (n == 1) then
  allocate(p(1,1))
  p(1,:) = x
else
  q => perms(x(2:n))
  k = ubound(q,1)
  allocate(p(k*n,n))
  p = 0
  do i = 1,n
    p(1+k*(i-1):k*i,1:i-1) = q(:,1:i-1)
    p(1+k*(i-1):k*i,i) = x(1)
    p(1+k*(i-1):k*i,i+1:) = q(:,i:)
  end do
end if
end function
end module

program topswort
use top
implicit none
integer :: x(10)
integer, pointer  :: p(:,:)
integer :: i, j, m

forall(i=1:10)
  x(i) = i
end forall

do i = 1,10
  p=>perms(x(1:i))
  m = 0
  do j = 1, ubound(p,1)
    m = max(m, f(p(j,:)))
  end do
  print "(i3,a,i3)", i,": ",m
end do  
end program
Task: Odd word problem

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

static int 
owp(int odd)
{
        int ch, ret;
        ch = getc(stdin);
        if (!odd) {
                putc(ch, stdout);
                if (ch == EOF || ch == '.')
                        return EOF;
                if (ispunct(ch))
                        return 0;
                owp(odd);
                return 0;
        } else {
                if (ispunct(ch))
                        return ch; 
                ret = owp(odd);
                putc(ch, stdout);
                return ret;
        }
}

int
main(int argc, char **argv)
{
        int ch = 1;
        while ((ch = owp(!ch)) != EOF) {
                if (ch)
                        putc(ch, stdout);
                if (ch == '.')
                        break;
        }
        return 0;
}










Fortran:       MODULE ELUDOM	
       INTEGER MSG,INF	
       LOGICAL DEFER	
       CONTAINS
        CHARACTER*1 RECURSIVE FUNCTION GET(IN)	
         INTEGER IN	
         CHARACTER*1 C	
          READ (IN,1,ADVANCE="NO",EOR=3,END=4) C	
    1     FORMAT (A1,$)	
    2     IF (("A"<=C .AND. C<="Z").OR.("a"<=C .AND. C<="z")) THEN	
            IF (DEFER) THEN	
              GET = GET(IN)	
              WRITE (MSG,1) C	
              RETURN		
            END IF		
           ELSE		
            DEFER = .NOT. DEFER	
          END IF	
    3     GET = C	
          RETURN	
    4     GET = CHAR(0)	
        END FUNCTION GET
      END MODULE ELUDOM	

      PROGRAM CONFUSED	
      USE ELUDOM	
      CHARACTER*1 C	
      MSG = 6	
      INF = 10	
      OPEN (INF,NAME = "Confused.txt",STATUS="OLD",ACTION="READ")	

Chew through the input. A full stop marks the end.
   10 DEFER = .FALSE.	
   11 C = GET(INF)		
      IF (ICHAR(C).LE.0) STOP		
      IF (C.NE." ") WRITE (MSG,12) C	
   12 FORMAT (A1,$)			
      IF (C.NE.".") GO TO 11	
      WRITE (MSG,"('')")	
      GO TO 10		
      END
Task: Memory layout of a data structure

C: struct RS232_data
{
  unsigned carrier_detect        : 1;
  unsigned received_data         : 1;
  unsigned transmitted_data      : 1;
  unsigned data_terminal_ready   : 1;
  unsigned signal_ground         : 1;
  unsigned data_set_ready        : 1;
  unsigned request_to_send       : 1;
  unsigned clear_to_send         : 1;
  unsigned ring_indicator        : 1;
};










Fortran:        TYPE RS232PIN9
        LOGICAL CARRIER_DETECT		
        LOGICAL RECEIVED_DATA		
        LOGICAL TRANSMITTED_DATA	
        LOGICAL DATA_TERMINAL_READY	
        LOGICAL SIGNAL_GROUND		
        LOGICAL DATA_SET_READY		
        LOGICAL REQUEST_TO_SEND		
        LOGICAL CLEAR_TO_SEND		
        LOGICAL RING_INDICATOR		
       END TYPE RS232PIN9
Task: Largest proper divisor of n

C: #include <stdio.h>

unsigned int lpd(unsigned int n) {
    if (n<=1) return 1;
    int i;
    for (i=n-1; i>0; i--)
        if (n%i == 0) return i;   
}

int main() {
    int i;
    for (i=1; i<=100; i++) {
        printf("%3d", lpd(i));
        if (i % 10 == 0) printf("\n");
    }
    return 0;
}










Fortran:        program LargestProperDivisors
       implicit none
       integer i, lpd
       do 10 i=1, 100
           write (*,'(I3)',advance='no') lpd(i)
 10        if (i/10*10 .eq. i) write (*,*)       
       end program
       
       integer function lpd(n)
       implicit none
       integer n, i
       if (n .le. 1) then
           lpd = 1
       else
           do 10 i=n-1, 1, -1
 10            if (n/i*i .eq. n) goto 20
 20        lpd = i
       end if
       end function
Task: Numbers with equal rises and falls

C: #include <stdio.h>


int riseEqFall(int num) {
    int rdigit = num % 10;
    int netHeight = 0;
    while (num /= 10) {
        netHeight += ((num % 10) > rdigit) - ((num % 10) < rdigit);
        rdigit = num % 10;
    }
    return netHeight == 0;
}


int nextNum() {
    static int num = 0;
    do {num++;} while (!riseEqFall(num));
    return num;
}

int main(void) {
    int total, num;
    
    
    printf("The first 200 numbers are: \n");
    for (total = 0; total < 200; total++)
        printf("%d ", nextNum());
    
    
    printf("\n\nThe 10,000,000th number is: ");
    for (; total < 10000000; total++) num = nextNum();
    printf("%d\n", num);
    
    return 0;
}










Fortran:       PROGRAM A296712
          INTEGER IDX, NUM, I
*         Index and number start out at zero
          IDX = 0
          NUM = 0 
*         Find and write the first 200 numbers
          WRITE (*,'(A)') 'The first 200 numbers are: '
          DO 100 I = 1, 200
              CALL NEXT NUM(IDX, NUM)
              WRITE (*,'(I4)',ADVANCE='NO') NUM
              IF (MOD(I,20).EQ.0) WRITE (*,*)
  100     CONTINUE
*         Find the 10,000,000th number
          WRITE (*,*)
          WRITE (*,'(A)',ADVANCE='NO') 'The 10,000,000th number is: '
  200     CALL NEXT NUM(IDX, NUM)
          IF (IDX.NE.10000000) GOTO 200
          WRITE (*,'(I8)') NUM
          STOP
      END    

*     Given index and current number, retrieve the next number
*     in the sequence.
      SUBROUTINE NEXT NUM(IDX, NUM) 
          INTEGER IDX, NUM
          LOGICAL IN SEQ
  100     NUM = NUM + 1
          IF (.NOT. IN SEQ(NUM)) GOTO 100
          IDX = IDX + 1           
      END
    
*     See whether N is in the sequence
      LOGICAL FUNCTION IN SEQ(N)
          INTEGER N, DL, DR, VAL, HEIGHT
*         Get first digit and divide value by 10
          DL = MOD(N, 10)
          VAL = N / 10
          HEIGHT = 0
  100     IF (VAL.NE.0) THEN
*             Retrieve digits by modulo and division
              DR = DL
              DL = MOD(VAL, 10)
              VAL = VAL / 10
*             Record rise or fall
              IF (DL.LT.DR) HEIGHT = HEIGHT + 1
              IF (DL.GT.DR) HEIGHT = HEIGHT - 1
              GOTO 100
          END IF
*         N is in the sequence if the final height is 0
          IN SEQ = HEIGHT.EQ.0
          RETURN
      END
Task: Length of an arc between two angles

C: #define PI 3.14159265358979323846
#define ABS(x)  (x<0?-x:x)

double arc_length(double radius, double angle1, double angle2) {
    return (360 - ABS(angle2 - angle1)) * PI / 180 * radius;
}

void main()
{
    printf("%.7f\n",arc_length(10, 10, 120));
}










Fortran: *-----------------------------------------------------------------------
* given:  polar coordinates of two points on a circle of known radius
* find:  length of the major arc between these points
*
*___Name_____Type___I/O___Description___________________________________
*   RAD      Real   In    Radius of circle, any unit of measure
*   ANG1     Real   In    Angle of first point, degrees
*   ANG2     Real   In    Angle of second point, degrees
*   MAJARC   Real   Out   Length of major arc, same units as RAD
*-----------------------------------------------------------------------
      FUNCTION MAJARC (RAD, ANG1, ANG2)
       IMPLICIT NONE
       REAL RAD, ANG1, ANG2, MAJARC

       REAL FACT                          
       PARAMETER (FACT = 3.1415926536 / 180.)
       REAL DIF

*       Begin
       MAJARC = 0.
       IF (RAD .LE. 0.) RETURN
       DIF = MOD(ABS(ANG1 - ANG2), 360.)   
       DIF = MAX(DIF, 360. - DIF)          
       MAJARC = RAD * DIF * FACT           
       RETURN
      END  

*-----------------------------------------------------------------------
      PROGRAM TMA
       IMPLICIT NONE
       INTEGER J
       REAL ANG1, ANG2, RAD, MAJARC, ALENG
       REAL DATARR(3,3)     
       DATA DATARR / 120.,  10., 10.,
     $                10., 120., 10.,
     $               180., 270., 10. /

       DO J = 1, 3
         ANG1 = DATARR(1,J)
         ANG2 = DATARR(2,J)
         RAD = DATARR(3,J)
         ALENG = MAJARC (RAD, ANG1, ANG2)        
         PRINT *, 'first angle: ', ANG1, ' second angle: ', ANG2, 
     $     ' radius: ', RAD, ' Length of major arc: ', ALENG
       END DO
      END
Task: Matrix with two diagonals

C: #include <stdio.h>

void specialMatrix(unsigned int n) {
    int i, j;
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            if (i == j || i + j == n - 1) {
                printf("%d ", 1);
            } else {
                printf("%d ", 0);
            }
        }
        printf("\n");
    }
}

int main() {
    specialMatrix(10); 
    printf("\n");
    specialMatrix(11); 
    return 0;
}










Fortran: program prog

    dimension a(100, 100)

    n = 7
	
    j1 = 1
    j2 = n
    do i = 1, n
        do j = 1, n
            a(i, j) = 0.
        end do
        a(i, j1) = 1
        a(i, j2) = 1
        j1 = j1 + 1
        j2 = j2 - 1
    end do

    do i = 1, n
        print *, (a(i, j), j=1,n)
    end do

end
Task: Words containing _the_ substring

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

int main() {
    char word[128];
    FILE *f = fopen("unixdict.txt","r");
    if (!f) {
        fprintf(stderr, "Cannot open unixdict.txt\n");
        return -1;
    }
    while (!feof(f)) {
        fgets(word, sizeof(word), f);
        
        
        if (strlen(word) > 12 && strstr(word,"the"))
            printf("%s",word);
    }
    fclose(f);
    return 0;
}










Fortran: program main
implicit none
integer :: lun
character(len=256) :: line
integer :: ios
   open(file='unixdict.txt',newunit=lun)
   do
      read(lun,'(a)',iostat=ios)line
      if(ios /= 0)exit
      if( index(line,'the') /= 0 .and. len_trim(line) > 11 ) then
         write(*,'(a)')trim(line)
      endif
   enddo
end program main
Task: Arena storage pool

C: #include <stdlib.h>










Fortran:       SUBROUTINE CHECK(A,N)	
       REAL A(:,:)	
       INTEGER N	
       REAL B(N,N)	
       INTEGER, ALLOCATABLE::TROUBLE(:)	
       INTEGER M

        M = COUNT(A(1:N,1:N).LE.0)	

        ALLOCATE (TROUBLE(1:M**3))	

        DEALLOCATE(TROUBLE)		
      END SUBROUTINE CHECK