Different Type of Pattern Program (Automata Program) in C
1) Write a Automata Program using 0 and 1
0 0
111
111
111
0 0
111
111
111
0 0
code :
#include<stdio.h>
void main(){
int i,j,rows,cols;
printf("enter rows and cols : ");
scanf("%d%d",&rows,&cols);
for(i=1;i<=rows;i++){
for(j=1;j<=cols;j++){
if((i==1 || i==rows) && (j==1 || j==cols))
printf("0");
else if((i==1 || i==rows) || (j==1 || j==cols))
printf(" ");
else
printf("1");
}
printf("\n");
}
}
void main(){
int i,j,rows,cols;
printf("enter rows and cols : ");
scanf("%d%d",&rows,&cols);
for(i=1;i<=rows;i++){
for(j=1;j<=cols;j++){
if((i==1 || i==rows) && (j==1 || j==cols))
printf("0");
else if((i==1 || i==rows) || (j==1 || j==cols))
printf(" ");
else
printf("1");
}
printf("\n");
}
}
Output :
2) Write a Automata Program using 0 and 1
1 1
111
111
111
1 1
111
111
111
1 1
Code :
#include<stdio.h>
void main(){
int i,j,rows,cols;
printf("enter rows and cols : ");
scanf("%d%d",&rows,&cols);
for(i=1;i<=rows;i++){
for(j=1;j<=cols;j++){
if((i==1 || i==rows) && (j==1 || j==cols))
printf("1");
else if((i==1 || i==rows) || (j==1 || j==cols))
printf(" ");
else
printf("1");
}
printf("\n");
}
}
void main(){
int i,j,rows,cols;
printf("enter rows and cols : ");
scanf("%d%d",&rows,&cols);
for(i=1;i<=rows;i++){
for(j=1;j<=cols;j++){
if((i==1 || i==rows) && (j==1 || j==cols))
printf("1");
else if((i==1 || i==rows) || (j==1 || j==cols))
printf(" ");
else
printf("1");
}
printf("\n");
}
}
Output :
Comments
Post a Comment