MATLAB: How to write this C program in MATLAB

cMATLAB

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,l,m,r;
int a[10][10];
int n=4;
clrscr();
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
a[i][j]=1;
}
}
for(i=1;i<=n;i++)
{
m=i;k=i;
for(j=1;j<=i;j++)
{
printf("[%d][%d]\t",m,j);
m--;
}
printf("\n");
}
if(k==n)
{
int p=2;
for(i=n;i>=1;i--)
{
r=k;
for(j=p;j<=n;j++)
{
printf("[%d][%d]\t",r,j);
r--;
}
printf("\n");
p++;
}
}
getch();
}

Best Answer

Opening braces { are not used. Closing braces } are "end" in MATLAB. A for loop like
for(j=1;j<=n;j++)
would look like
for j = 1 : n
in MATLAB. printf() is done by fprintf().
p++; would look like p=p+1. Similarly -- would look like p=p-1.
Then you should look over the Getting Started section of the help.
Related Question