Skip to main content

Posts

Showing posts with the label C

Different Type of Pattern Program ( Automata Program page 2 ) in C

Different Type of Pattern Program ( Automata Program ) in C 1) Write a Automata program using 0 and 1  000 0    0 0    0 0    0  000 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(" "); else if((i==1 || i==rows) || (j==1 || j==cols)) printf("0"); else printf(" "); } printf("\n"); } } Output : 2) Write a Automata program using 0 and 1 10101 01010 10101 01010 10101 Code : #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if((i%2==0 || j%2==1)&&(i%2==1 || j%2==0)) printf("1"); else printf("0"); } printf("\n"); } } Output :

Different Type of Pattern Program (Automata Program) in C

       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 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"); } } Output :  2) Write a Automata Program using 0 and 1 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

C Program Converts Temperature Celsius to Fahrenheit

Write a program to C Program Converts Temperature Celsius to Fahrenheit Code:  #include<stdio.h> void main(){ int cel,far; printf("enter temparature in celsius : "); scanf("%d", &cel); far=((1.8*cel) + 32); printf("farenhait temparature is : %d\n",far); } Output: 

C program Print Prime Number between 0 to 100

How to print prime number Between 0 to 100 Code: #include<stdio.h> void main(){ int i,j; for(i=2;i<100;i++){ for(j=2;j<=i;j++){ if(i==j) printf("%d\n",i); else if(i%j == 0) break; } } } Output:

Automata Program Using C program

1) write Automata Program using 1 and 0 10101 01010 10101 01010 10101 Code : #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if((i%2==0 || j%2==1)&&(i%2==1 || j%2==0)) printf("1"); else printf("0"); } printf("\n"); } }  Output :   2) write Automata Program using 1 and 0 11111 10001 10001 10001 11111  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 printf("0"); } printf("\n"); } } Output:            

Automata Program Using C program

1) write Automata Program using 1 and 0 01010 10101 01010 10101 01010   code : #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if((i%2==0 || j%2==1)&&(i%2==1 || j%2==0)) printf("0"); else printf("1"); } printf("\n"); } } Output :   2) write Automata Program using 1 and 0 01110 10001 10001 10001 01110   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("1"); else printf("0"); } printf("\n"); } } Output :

Automata Program Using C program

1) write Automata Program using 1 and 0 11111 10101 11111 10101 11111 Code :  #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(i%2==0 && j%2==0) printf("0"); else printf("1"); } printf("\n"); } } OupPut :    2) write Automata Program using 1 and 0  111 1    1 1    1 1    1  111  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(" "); else if((i==1 || i==rows) || (j==1 || j==cols)) printf("1"); else printf(" "); } printf("\n"); } } Output: 

Automata Program Using C program

write Automata Program using 1 and 0  000 0    0 0    0 0    0  000  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(" "); else if((i==1 || i==rows) || (j==1 || j==cols)) printf("0"); else printf(" "); } printf("\n"); } } Output: 

C program Code to write Automata Program

 write Automata Program using 1 and 0  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"); } } Output:

C program Code to write Automata Program

 write Automata Program using 1 and 0  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("1"); else if((i==1 || i==rows) || (j==1 || j==cols)) printf(" "); else printf("1"); } printf("\n"); } } Output:

C program Code to write Automata Program

 write Automata Program using 1 and 0 10101 01010 10101 01010 10101 Code: #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if((i%2==0 || j%2==1)&&(i%2==1 || j%2==0)) printf("1"); else printf("0"); } printf("\n"); } } Output:  

C program Code to write Automata program

Write a program to half pyramid using 1 and 0 10101 01010 10101 01010 10101   Code: #include<stdio.h> int main(){ int i,j,n; printf("enter a number : "); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if((i%2==0 || j%2==1)&&(i%2==1 || j%2==0)) printf("1"); else printf("0"); } printf("\n"); } } Output:

C program to swap two number

C program to Swap two Number Code: #include<stdio.h> void main(){ int n1,n2,temp; printf("enter two number :"); scanf("%d %d", &n1,&n2); temp=n1; n1=n2; n2=temp; printf("after swaping two number %d  %d\n",n1,n2); } Output:

Matrix Substruction Using C program

Matrix Substruction Using C program Code: #include<stdio.h> void main(){ int first[100][100],second[100][100],sum[100][100],r,c,i,j; printf("enter row and colume :"); scanf("%d%d", &r,&c); printf("enter first matrix element : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ scanf("%d", &first[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ printf(" %d ", first[i][j]); } printf("\n"); } printf("enter second matrix element : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ scanf("%d", &second[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ printf(" %d ", second[i][j]); } printf("\n"); } printf("substraction  of the two matrix : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ sum[i][j]=first[i][j] - second[i][j]; printf(" %d ",sum[i][j]); } printf("\n"); } } Output:

Matrix Addition using C Program

Matrix Addition using C Program Code:  #include<stdio.h> void main(){ int first[100][100],second[100][100],sum[100][100],r,c,i,j; printf("enter row and colume :"); scanf("%d%d", &r,&c); printf("enter first matrix element : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ scanf("%d", &first[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ printf(" %d ", first[i][j]); } printf("\n"); } printf("enter second matrix element : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ scanf("%d", &second[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ printf(" %d ", second[i][j]); } printf("\n"); } printf("substraction  of the two matrix : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ sum[i][j]=first[i][j] - second[i][j]; printf(" %d ",sum[i][j]); } printf("\n"); } } Output:

Create a Dynamic Matrix using C Program

Create a Dynamic Matrix using C Program Code: #include<stdio.h> void main(){ int a[100][100],r,c,i,j; printf("enter row and colume :"); scanf("%d%d", &r,&c); printf("enter matrix element : \n"); for(i=0;i<r;i++){ for(j=0;j<c;j++){ scanf("%d", &a[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ printf("%d", a[i][j]); if(j==c-1){ printf("\n"); } } } } Output:

Create a simple static Matrix using C programming

Create a simple static Matrix using C programming Code: #include<stdio.h> void main(){ int a[2][2]={{1,2}, {3,4}}; int i,j; for(i=0;i<2;i++){ for(j=0;j<2;j++){ printf("%d", a[i][j]); if(j==1){ printf("\n"); } } } } Output:

Binary Search in c

Code: #include<stdio.h> void main(){ int a[100],i,n,mid,high,low,search; printf("enter length of array : "); scanf("%d",&n); printf("enter element in array in assending order: "); for(i=1;i<=n;i++){ scanf("%d",&a[i]); } printf("the arrray which you enterd :"); for(i=1;i<=n;i++){ printf("%d ",a[i]); } printf("\nenter a element which you want to search : "); scanf("%d",&search); low=0; high=n-1; mid=(low+high)/2; while(low<=high){ if(a[mid]<search) low=low+1; else if(a[mid]==search){ printf("the element is found %d at location %d : ",search,mid); break; } else high=mid-1; mid=(low+high)/2; } if(low>high) printf("%d element is not present in the array",search); } Output:  

Linear Search in C program

Code : #include<stdio.h> void main(){ int a[10],i,x; for(i=0;i<10;i++){ printf("enter values on arrey : "); scanf("%d",&a[i]); } printf("enter a value which you want to find"); scanf("%d",&x); for(i=0;i<10;i++){ if(a[i]==x){ printf("the number is found : %d", x); break; } if(a[i]==a[9]){ printf("the number is not found : %d",x); } } } Output:   

C program write a Array in descending Order

 code: #include<stdio.h> void main(){ int i,j,n,a[100],temp=0; printf("enter total number present in an array : "); scanf("%d",&n); printf("enter elements in an array : "); for(i=1;i<=n;i++){ scanf("%d", &a[i]); } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(a[i]<=a[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; } } } printf("array after sort  : "); for(i=n;i>=1;--i){ printf("%d ",a[i]); } } OutPut: