EmbLogic's Blog

Author Archives: Jyoti Singh

2 Dimensional Array

CODE : #include<stdio.h> int main() { int **a,**b; int i,j; a=(int **)malloc(sizeof(int)*10); b=(int **)malloc(sizeof(int)*10); for(i=0;i<10;i++) { *(a+i)=(int *)malloc(sizeof(int)*10); *(b+i)=(int *)malloc(sizeof(int)*10); } printf(“Enter Elements of Array is:\n”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf(“%d”,(*(a+i)+j)); } } printf(“Elements are:\n”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“%d\t”,*(*(a+i)+j)); … Continue reading

Posted in Data Structures with C | Leave a comment

write a program to add two distances in feet and inches?

code : #include<stdio.h> #include<stdlib.h> struct distance { int feet,meter; float inch,cm; }; struct distance display(struct distance d1,struct distance d2,struct distance d3,struct distance d4); struct distance convert(struct distance d3); struct distance addlist(struct distance d1 ,struct distance d2); struct distance input (); … Continue reading

Posted in Data Structures with C | Leave a comment

Write a program to check the underlying architecture of the system?

CODE: #include<stdio.h> union endian { int i; unsigned char ch[4]; }e; int main() { e.i=0XAABBCCDD; if(e.ch[0]==0XDD) { printf(“Underlying architecture is Little endian\n”); } else { printf(“Underlying architecture is Bigendian\n”); } printf(“%#X\n”,e.i); printf(“%#X\n”,e.ch[0]); printf(“%#X\n”,e.ch[1]); printf(“%#X\n”,e.ch[2]); printf(“%#X\n”,e.ch[3]); }

Posted in Data Structures with C | Leave a comment

Write a Program to Add two number using bitwise operators?

CODE: #include<stdio.h> #include<stdlib.h> int main() { int a,b,sum,carry; printf(“Enter Values\n”); scanf(“%d%d”,&a,&b); carry=a&b; printf(“carry:%d\n”,carry); sum=a^b; printf(“Sum:%d\n”,sum); while(carry) { carry<<=1; printf(“carry:…%d\n”,carry); a=sum; printf(“a:%d\n”,a); b=carry; printf(“b:%d\n”,b); sum=a^b; printf(“sum:%d\n”,sum); carry=a&b; printf(“carry:…%d\n”,carry); } printf(“…..Sum=%d…..\n”,sum); }

Posted in Data Structures with C | Leave a comment

Write a program to find the factorial using recursion?

CODE : #include<stdio.h> #include<stdlib.h> int fact (int ); int main() { int n; printf(“Enter number whose factroialu want u find\n”); scanf(“%d”,&n); printf(“Factorial of %d is %d\n”,n,fact(n)); return 0; } int fact( int n ) { if(n!=1) return n*fact(n-1); }

Posted in Data Structures with C | Leave a comment

Write a program to find the Fibonacci series using recursion?

code : #include<stdio.h> #include<stdlib.h> int fibo(int); int main() { int n,i,k; printf(“Enter maximum length of fibonacci series\n”); scanf(“%d”,&n); for(i=0;i<n;i++) { printf(“%d “,fibo(i)); } } int fibo(int i) { if(i==0) return 0; else if(i==1) return 1; else return (fibo(i-1)+fibo(i-2)); }

Posted in Data Structures with C | Leave a comment

Write a Program to delete element in array?

code : #include<stdio.h> #include<stdlib.h> int main() { system(“clear”); int n,el,j,i,flag=0; printf(“Enter Max Size\n”); scanf(“%d”,&n); int a[n]; printf(“Enter Element\n”); for(i=0;i<n;i++) { scanf(“%d”,&a[i]); } printf(“Enter Element U Want To Delete\n”); scanf(“%d”,&el); for(i=0;i<n;i++) { if(a[i]==el) { flag=1; for(j=i;j<n;j++) { a[j]=a[j+1]; } } } … Continue reading

Posted in Data Structures with C | Leave a comment

Write a Program to merge two matrix?

code: #include<stdio.h> #include<stdlib.h> int main() { system(“clear”); int a[10],b[10],c[20],m,n,o,i,j,k,temp; printf(“Enter size of Array1\n”); scanf(“%d”,&n); printf(“Enter size of Array2\n”); scanf(“%d”,&m); o=m+n; printf(“Enter Elements of Array1\n”); for(i=0;i<n;i++) { scanf(“%d”,&a[i]); } printf(“Enter Elements of Array2\n”); for(i=0;i<m;i++) { scanf(“%d”,&b[i]); } for(i=0;i<n;i++) { for(j=0;j<n-1-i;j++) { … Continue reading

Posted in Data Structures with C | Leave a comment

Write a Program for quadric equation?

code: #include<stdio.h> #include<math.h> int main() { int a,b,c,d,e,f; float s,g,h,r1,r2; printf(“Enter constant:”); scanf(“%d%d%d”,&a,&b,&c); d=(b*b-4*a*c); if(a==0 && b==0) { printf(“There is no solution\n”); } else if(a==0) { e=-c/b; printf(“There is only one root:%d\n”,e); } else if(d<1) { printf(“Roots are complex\n”); f=abs(d); … Continue reading

Posted in Data Structures with C | Leave a comment

Write a program to concatenate two string?

CODE : #include<stdio.h> #include<stdlib.h> int main() { char *str1,*str2; int i,j,k,m=0,o; str1=(char *)malloc(sizeof(char)); str2=(char *)malloc(sizeof(char)); printf(“Enter String1:”); gets(str1); printf(“Enter String2:”); gets(str2); for(i=0;str1[i]!=”;i++) { printf(“String[%d]=%c\n”,i,*(str1+i)); } for(j=0;str2[j]!=”;j++) { printf(“String[%d]=%c\n”,j,*(str2+j)); } printf(“string1: %s i is %d\n”,str1,i); printf(“string2: %s j is %d\n”,str2,j); o=i+j; … Continue reading

Posted in Data Structures with C | Leave a comment

Write a program to reverse the Array?

CODE: #include<stdio.h> #include<stdlib.h> int main() { int n,temp,i,j; printf(“Enter size of Array\n”); scanf(“%d”,&n); int a[n]; printf(“Enter Elements \n”); for(i=0;i<n;i++) { scanf(“%d”,&a[i]); } printf(“Elements Are:\n”); for(i=0;i<n;i++) { printf(“%d\t”,a[i]); } printf(“\n”); for(i=0,j=n-1;i<=n/2;i++,j–) { temp=a[i]; a[i]=a[j]; a[j]=temp; } printf(“Reversed array:\n”); for(i=0;i<n;i++) { printf(“a[%d]=%d\n”,i,a[i]); … Continue reading

Posted in Data Structures with C | Leave a comment

Write a program to Transpose the Matrix?

#include<stdio.h> #include<stdlib.h> int main() { int r,c,i,j,a[10][10],t[10][10]; printf(“Enter Max Size\n”); scanf(“%d”,&r); printf(“Enter Column\n”); scanf(“%d”,&c); printf(“Enter Element of Matrix1\n”); for(i=0;i<r;i++) { for(j=0;j<c;j++) { scanf(“%d”,&a[i][j]); } } printf(“Elements are:\n”); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf(“%d\t”,a[i][j]); } printf(“\n”); } for(i=0;i<r;i++) { for(j=0;j<c;j++) { t[j][i]=a[i][j]; … Continue reading

Posted in Data Structures with C | Leave a comment

binarysearch using pointers

#include<stdio.h> 2 #include<stdlib.h> 3 int input(int,int *); 4 int search(int *,int,int); 5 int main() 6 { 7 8         int size=10; 9         int * ptr; 10         int i,c,s,key; 11         ptr=(int*)malloc(sizeof(int)*size); 12         c=input(size,ptr); 13         printf(“\n matrix printed are:”); 14         for(i=0;i<size;i++) 15         { … Continue reading

Posted in Data Structures with C | Leave a comment

multiply array

RCS file: mularray.c,v Working file: mularray.c head: 1.2 branch: locks: strict jyotisingh: 1.2 access list: symbolic names: keyword substitution: kv total revisions: 2;    selected revisions: 2 description: input matrix a input matrix b logic for multiplication print matrix —————————- revision … Continue reading

Posted in Data Structures with C | Leave a comment