0% found this document useful (0 votes)
45 views

C and Matlab Comparison

This document compares the syntax for variables, operators, and control flow in Fortran, Matlab, and C/C++ programming languages. It shows that Fortran uses keywords like integer, real, and logical for variable types, while Matlab and C/C++ use specific variable type names like int, float, and bool. For operators, it lists the symbols used for arithmetic, comparison, logical, and assignment operations. It also outlines the syntax for basic control structures like if/else statements, for loops, and while loops.

Uploaded by

Luat Vu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

C and Matlab Comparison

This document compares the syntax for variables, operators, and control flow in Fortran, Matlab, and C/C++ programming languages. It shows that Fortran uses keywords like integer, real, and logical for variable types, while Matlab and C/C++ use specific variable type names like int, float, and bool. For operators, it lists the symbols used for arithmetic, comparison, logical, and assignment operations. It also outlines the syntax for basic control structures like if/else statements, for loops, and while loops.

Uploaded by

Luat Vu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Embedded Software for Aerospace Systems Fall 2009

Dr. Gil Crouse

Syntax comparison between Fortran, Matlab, and C/C++


Variables Fortran
integer i real x double precision x, y logical flag character str(25)

Matlab

C/C++
int i; float x; double x, y; bool flag; char str[25];

Operators Fortran
Exponent Std Math Equals Not Equal Less/Greater than Less/Greater than or equal to Logical not Logical and Logical or Binary and Binary or Increment Decrement Conditional x**y * / + == .eq. /= .ne. < .lt. <= .not. .and. .or. .le.

Matlab
x^y * / + == ~= < > <= >= not and or

C/C++
pow(x, y) * / + == != < > <= >= ! && || & | ++ -(?:)

> >=

.gt. .ge.

Control Flow Fortran


function myFunction(arg) . . . myFunction = ans end if (i == 0) then . . . else if (i > 10) then . . . else . . . end if

Matlab
function ans = myFunction(arg) . . . end

C/C++
int myFunction(double arg) { . . . return ans; } if (i == 0) { . . . } else if (i > 10) { . . . } else { . . . } for (int i = 0; i < n; i++) { . . . continue; //skip to next break; //exit loop } while (i < n) { . . . }

if i == 0 . . . elseif i > 10 . . . else . . . end

integer i, n do i = 0, n-1 . . . end do do if (i >= n) exit . . . end do

for i = 0:n . . . continue % skip to next break % exit loop end while i < n . . . end

You might also like