WeixiangYan/CodeTransOcean huggingface dataset:
Task: Pascal's triangle




Go: package main

import "fmt"

func printTriangle(n int) {
    
    if n <= 0 {
        return
    }
    fmt.Println(1)
    if n == 1 {
        return
    }
    
    a := make([]int, (n+1)/2)
    a[0] = 1
    for row, middle := 1, 0; row < n; row++ {
        
        even := row&1 == 0
        if even {
            a[middle+1] = a[middle] * 2
        }
        for i := middle; i > 0; i-- {
            a[i] += a[i-1]
        }
        
        for i := 0; i <= middle; i++ {
            fmt.Print(a[i], " ")
        }
        if even {
            middle++
        }
        for i := middle; i >= 0; i-- {
            fmt.Print(a[i], " ")
        }
        fmt.Println("")
    }
}

func main() {
    printTriangle(4)
}
Task: Pascal's triangle



C#: using System;

namespace RosettaCode {

    class PascalsTriangle {

        public static void CreateTriangle(int n) {
            if (n > 0) {
                for (int i = 0; i < n; i++) {
                    int c = 1;
                    Console.Write(" ".PadLeft(2 * (n - 1 - i)));
                    for (int k = 0; k <= i; k++) {
                        Console.Write("{0}", c.ToString().PadLeft(3));
                        c = c * (i - k) / (k + 1);
                    }
                    Console.WriteLine();
                }
            }
        }

        public static void Main() {
            CreateTriangle(8);
        }
    }
}








Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle


C++: #include <iostream>
#include <algorithm>
#include<cstdio>
using namespace std;
void Pascal_Triangle(int size) {

	int a[100][100];
	int i, j;

	
	for (i = 1; i <= size; i++) {
		a[i][1] = a[1][i] = 1;
	}
	
	
	for (i = 2; i <= size; i++) {
		for (j = 2; j <= size - i; j++) {
			if (a[i - 1][j] == 0 || a[i][j - 1] == 0) {
				break;
			}
			a[i][j] = a[i - 1][j] + a[i][j - 1];
		}
	}

	
	
	
	
	int row,space;
	for (i = 1; i < size; i++) {
		space=row=i;
		j=1;
		
		while(space<=size+(size-i)+1){
			 cout<<" ";
			 space++;
		 }
		
		while(j<=i){
			if (a[row][j] == 0){
				   break;
			   }
			
			if(j==1){
				printf("%d",a[row--][j++]);
			}
			else
				printf("%6d",a[row--][j++]);
		}
			cout<<"\n\n";
	}
	
}

int main()
{
	
	
	int size;
	cin>>size;
	Pascal_Triangle(size);
}

}









Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle

C: #include <stdio.h>

void pascaltriangle(unsigned int n)
{
  unsigned int c, i, j, k;

  for(i=0; i < n; i++) {
    c = 1;
    for(j=1; j <= 2*(n-1-i); j++) printf(" ");
    for(k=0; k <= i; k++) {
      printf("%3d ", c);
      c = c * (i-k)/(k+1);
    }
    printf("\n");
  }
}

int main()
{
  pascaltriangle(8);
  return 0;
}










Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle





Java: import java.util.ArrayList;
...
public static void genPyrN(int rows){
	if(rows < 0) return;
	
	ArrayList<Integer> last = new ArrayList<Integer>();
	last.add(1);
	System.out.println(last);
	for(int i= 1;i <= rows;++i){
		
		ArrayList<Integer> thisRow= new ArrayList<Integer>();
		thisRow.add(last.get(0)); 
		for(int j= 1;j < i;++j){
			
			thisRow.add(last.get(j - 1) + last.get(j));
		}
		thisRow.add(last.get(0)); 
		last= thisRow;
		System.out.println(thisRow);
	}
}






Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle







Python: def pascal(n):
   
   row = [1]
   k = [0]
   for x in range(max(n,0)):
      print row
      row=[l+r for l,r in zip(row+k,k+row)]
   return n>=1




Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle








VB: Option Base 1
Private Sub pascal_triangle(n As Integer)
    Dim odd() As String
    Dim eve() As String
    ReDim odd(1)
    ReDim eve(2)
    odd(1) = "  1"
    For i = 1 To n
        If i Mod 2 = 1 Then
            Debug.Print String$(2 * n - 2 * i, " ") & Join(odd, " ")
            eve(1) = "  1"
            ReDim Preserve eve(i + 1)
            For j = 2 To i
                eve(j) = Format(CStr(Val(odd(j - 1)) + Val(odd(j))), "@@@")
            Next j
            eve(i + 1) = "  1"
        Else
            Debug.Print String$(2 * n - 2 * i, " ") & Join(eve, " ")
            odd(1) = "  1"
            ReDim Preserve odd(i + 1)
            For j = 2 To i
                odd(j) = Format(CStr(Val(eve(j - 1)) + Val(eve(j))), "@@@")
            Next j
            odd(i + 1) = "  1"
        End If
    Next i
End Sub
Public Sub main()
    pascal_triangle 13
End Sub



Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle






PHP: <?php

function tre($n) {
  $ck=1;
  $kn=$n+1;
    
 if($kn%2==0) {
 $kn=$kn/2;
 $i=0;
  }
 else
  {

  $kn+=1;
  $kn=$kn/2;
  $i= 1;
}

 for ($k = 1; $k <= $kn-1; $k++) { 
   $ck = $ck/$k*($n-$k+1);
   $arr[] = $ck;
   echo  "+" . $ck ;
 
  }
 

if ($kn>1) {
  echo $arr[i];
  $arr=array_reverse($arr);
 for ($i; $i<= $kn-1; $i++) {
 echo  "+" . $arr[$i]  ;
     }
 
   }
 
 }

 while ($n<=20) {
 ++$n;
 echo tre($n);
 echo "<br/>";
}
 
 
?>





Fortran: PROGRAM Pascals_Triangle

  CALL Print_Triangle(8)

END PROGRAM Pascals_Triangle

SUBROUTINE Print_Triangle(n)

  IMPLICIT NONE
  INTEGER, INTENT(IN) :: n
  INTEGER :: c, i, j, k, spaces

  DO i = 0, n-1
     c = 1
     spaces = 3 * (n - 1 - i)
     DO j = 1, spaces
        WRITE(*,"(A)", ADVANCE="NO") " "
     END DO
     DO k = 0, i
        WRITE(*,"(I6)", ADVANCE="NO") c
        c = c * (i - k) / (k + 1)
     END DO
     WRITE(*,*)
  END DO

END SUBROUTINE Print_Triangle
Task: Pascal's triangle






PHP: <?php

function tre($n) {
  $ck=1;
  $kn=$n+1;
    
 if($kn%2==0) {
 $kn=$kn/2;
 $i=0;
  }
 else
  {

  $kn+=1;
  $kn=$kn/2;
  $i= 1;
}

 for ($k = 1; $k <= $kn-1; $k++) { 
   $ck = $ck/$k*($n-$k+1);
   $arr[] = $ck;
   echo  "+" . $ck ;
 
  }
 

if ($kn>1) {
  echo $arr[i];
  $arr=array_reverse($arr);
 for ($i; $i<= $kn-1; $i++) {
 echo  "+" . $arr[$i]  ;
     }
 
   }
 
 }

 while ($n<=20) {
 ++$n;
 echo tre($n);
 echo "<br/>";
}
 
 
?>
Task: Pascal's triangle






PHP: <?php

function tre($n) {
  $ck=1;
  $kn=$n+1;
    
 if($kn%2==0) {
 $kn=$kn/2;
 $i=0;
  }
 else
  {

  $kn+=1;
  $kn=$kn/2;
  $i= 1;
}

 for ($k = 1; $k <= $kn-1; $k++) { 
   $ck = $ck/$k*($n-$k+1);
   $arr[] = $ck;
   echo  "+" . $ck ;
 
  }
 

if ($kn>1) {
  echo $arr[i];
  $arr=array_reverse($arr);
 for ($i; $i<= $kn-1; $i++) {
 echo  "+" . $arr[$i]  ;
     }
 
   }
 
 }

 while ($n<=20) {
 ++$n;
 echo tre($n);
 echo "<br/>";
}
 
 
?>






Ada: package Pascal is
   
   type Row is array (Natural range <>) of Natural;
   
   function Length(R: Row) return Positive;
   
   function First_Row(Max_Length: Positive) return Row;
   
   function Next_Row(R: Row) return Row;
   
end Pascal;
Task: Logical operations



C#: using System;

namespace LogicalOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            bool a = true, b = false;
            Console.WriteLine("a and b is {0}", a && b);
            Console.WriteLine("a or b is {0}", a || b);
            Console.WriteLine("Not a is {0}", !a);
            Console.WriteLine("a exclusive-or b is {0}", a ^ b);
        }
    }
}









Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations

C: if(myValue == 3 && myOtherValue == 5){
myResult = true;
}











Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations


C++: void print_logic(bool a, bool b)
{
  std::cout << std::boolalpha; 
  std::cout << "a and b is " << (a && b) << "\n";
  std::cout << "a or b is " << (a || b) << "\n";
  std::cout << "not a is " << (!a) << "\n";
}










Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations




Go: func printLogic(a, b bool) {
    fmt.Println("a and b is", a && b)
    fmt.Println("a or b is", a || b)
    fmt.Println("not a is", !a)
}








Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations





Java: boolean a = true;
boolean b = false;
System.Debug('a AND b: ' + (a && b));
System.Debug('a OR b: ' + (a || b));
System.Debug('NOT a: ' + (!a));
System.Debug('a XOR b: ' + (a ^ b));







Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations







Python: def logic(a, b):
    print('a and b:', a and b)
    print('a or b:', a or b)
    print('not a:', not a)





Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations








VB: Function Test(ByVal a As Boolean, ByVal b As Boolean)
    Console.WriteLine("And " & a And b)
    Console.WriteLine("Or " & a Or b)
    Console.WriteLine("Not " & Not a)
    Console.WriteLine("Xor " & a Xor b)
    Console.WriteLine("And, short-circuited " & a AndAlso b)
    Console.WriteLine("Or, short-circuited " & a OrElse b)
End Function




Ada: procedure Print_Logic(A : Boolean; B : Boolean) is
begin
   Put_Line("A and B is " & Boolean'Image(A and B));
   Put_Line("A or B  is " & Boolean'Image(A or B));
   Put_Line("A xor B is " & Boolean'Image(A xor B));
   Put_Line("not A   is " & Boolean'Image(not A));
end Print_Logic;
Task: Logical operations

C: if(myValue == 3 && myOtherValue == 5){
myResult = true;
}
Task: Logical operations



C#: using System;

namespace LogicalOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            bool a = true, b = false;
            Console.WriteLine("a and b is {0}", a && b);
            Console.WriteLine("a or b is {0}", a || b);
            Console.WriteLine("Not a is {0}", !a);
            Console.WriteLine("a exclusive-or b is {0}", a ^ b);
        }
    }
}
Task: Logical operations


C++: void print_logic(bool a, bool b)
{
  std::cout << std::boolalpha; 
  std::cout << "a and b is " << (a && b) << "\n";
  std::cout << "a or b is " << (a || b) << "\n";
  std::cout << "not a is " << (!a) << "\n";
}
Task: Logical operations





Java: boolean a = true;
boolean b = false;
System.Debug('a AND b: ' + (a && b));
System.Debug('a OR b: ' + (a || b));
System.Debug('NOT a: ' + (!a));
System.Debug('a XOR b: ' + (a ^ b));
Task: Logical operations







Python: def logic(a, b):
    print('a and b:', a and b)
    print('a or b:', a or b)
    print('not a:', not a)
Task: Logical operations








VB: Function Test(ByVal a As Boolean, ByVal b As Boolean)
    Console.WriteLine("And " & a And b)
    Console.WriteLine("Or " & a Or b)
    Console.WriteLine("Not " & Not a)
    Console.WriteLine("Xor " & a Xor b)
    Console.WriteLine("And, short-circuited " & a AndAlso b)
    Console.WriteLine("Or, short-circuited " & a OrElse b)
End Function
Task: Logical operations




Go: func printLogic(a, b bool) {
    fmt.Println("a and b is", a && b)
    fmt.Println("a or b is", a || b)
    fmt.Println("not a is", !a)
}
Task: Logical operations



C#: using System;

namespace LogicalOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            bool a = true, b = false;
            Console.WriteLine("a and b is {0}", a && b);
            Console.WriteLine("a or b is {0}", a || b);
            Console.WriteLine("Not a is {0}", !a);
            Console.WriteLine("a exclusive-or b is {0}", a ^ b);
        }
    }
}








Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations


C++: void print_logic(bool a, bool b)
{
  std::cout << std::boolalpha; 
  std::cout << "a and b is " << (a && b) << "\n";
  std::cout << "a or b is " << (a || b) << "\n";
  std::cout << "not a is " << (!a) << "\n";
}









Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations

C: if(myValue == 3 && myOtherValue == 5){
myResult = true;
}










Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations





Java: boolean a = true;
boolean b = false;
System.Debug('a AND b: ' + (a && b));
System.Debug('a OR b: ' + (a || b));
System.Debug('NOT a: ' + (!a));
System.Debug('a XOR b: ' + (a ^ b));






Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations







Python: def logic(a, b):
    print('a and b:', a and b)
    print('a or b:', a or b)
    print('not a:', not a)




Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations








VB: Function Test(ByVal a As Boolean, ByVal b As Boolean)
    Console.WriteLine("And " & a And b)
    Console.WriteLine("Or " & a Or b)
    Console.WriteLine("Not " & Not a)
    Console.WriteLine("Xor " & a Xor b)
    Console.WriteLine("And, short-circuited " & a AndAlso b)
    Console.WriteLine("Or, short-circuited " & a OrElse b)
End Function



Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations






PHP: function print_logic($a, $b)
{
    echo "a and b is ", $a && $b ? 'True' : 'False', "\n";
    echo "a or b is ", $a || $b ? 'True' : 'False', "\n";
    echo "not a is ", ! $a ? 'True' : 'False', "\n";
}





Fortran:        SUBROUTINE PRNLOG(A, B)
       LOGICAL A, B
       PRINT *, 'a and b is ', A .AND. B
       PRINT *, 'a or b is ', A .OR. B
       PRINT *, 'not a is ', .NOT. A
       
C       You did not ask, but the following logical operators are also standard
C       since ANSI FORTRAN 66 
C       =======================================================================
       
C       This yields the same results as .EQ., but has lower operator precedence
C       and only works with LOGICAL operands:
       PRINT *, 'a equivalent to b is ', A .EQV. B
       
C       This yields the same results as .NE., but has lower operator precedence
C       and only works with LOGICAL operands (this operation is also commonly
C       called "exclusive or"):
       PRINT *, 'a not equivalent to b is ', A .NEQV. B
       END
Task: Logical operations

C: if(myValue == 3 && myOtherValue == 5){
myResult = true;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. print-logic.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  result                  PIC 1 USAGE BIT.

       LINKAGE SECTION.
       01  a                       PIC 1 USAGE BIT.
       01  b                       PIC 1 USAGE BIT.

       PROCEDURE DIVISION USING a, b.
           COMPUTE result = a B-AND b
           DISPLAY "a and b is " result

           COMPUTE result = a B-OR b
           DISPLAY "a or b is " result

           COMPUTE result = B-NOT a
           DISPLAY "Not a is " result

           COMPUTE result = a B-XOR b
           DISPLAY "a exclusive-or b is " result

           GOBACK
           .
Task: Logical operations



C#: using System;

namespace LogicalOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            bool a = true, b = false;
            Console.WriteLine("a and b is {0}", a && b);
            Console.WriteLine("a or b is {0}", a || b);
            Console.WriteLine("Not a is {0}", !a);
            Console.WriteLine("a exclusive-or b is {0}", a ^ b);
        }
    }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. print-logic.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  result                  PIC 1 USAGE BIT.

       LINKAGE SECTION.
       01  a                       PIC 1 USAGE BIT.
       01  b                       PIC 1 USAGE BIT.

       PROCEDURE DIVISION USING a, b.
           COMPUTE result = a B-AND b
           DISPLAY "a and b is " result

           COMPUTE result = a B-OR b
           DISPLAY "a or b is " result

           COMPUTE result = B-NOT a
           DISPLAY "Not a is " result

           COMPUTE result = a B-XOR b
           DISPLAY "a exclusive-or b is " result

           GOBACK
           .