EmbLogic's Blog

Multiple Client – server Program using PIPE and Signal.

PIPE to mean connecting a data flow from one process to another.PIPE is passed (a pointer to) an array of two integer file descriptors.It fills the array with two new file descriptors and returns a zero. On failure, it returns -1.The two file descriptors returned are connected in a special way. Any data written to file_descriptor[1] can be read back from file_descriptor[0]. The data is processed in a first in, first out basis, usually abbreviated to FIFO.

Fd[0] = read

fd[1] = write

CODE:

RCS file: ./header.h,v
Working file: ./header.h
head: 1.3
branch:
locks: strict
root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
This is the base header file for the project 3_client server ipc technique using pipe and signals
—————————-
revision 1.3 locked by: root;
date: 2015/08/04 06:05:54; author: root; state: Exp; lines: +1 -0
Included color.h
—————————-
revision 1.2
date: 2015/08/03 18:37:10; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================RCS file: ./req_add.c,v
Working file: ./req_add.c
head: 1.10
branch:
locks: strict
root: 1.10
access list:
symbolic names:
keyword substitution: kv
total revisions: 10; selected revisions: 10
description:
This is Requesting client named adder
—————————-
revision 1.10 locked by: root;
date: 2015/08/31 18:06:46; author: root; state: Exp; lines: +7 -0
Included comment
—————————-
revision 1.9
date: 2015/08/04 07:09:47; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.8
date: 2015/08/04 07:07:31; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.7
date: 2015/08/04 06:59:09; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 06:56:03; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:06:04; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:38:24; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:47; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:15; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================RCS file: ./req_sub.c,v
Working file: ./req_sub.c
head: 1.8
branch:
locks: strict
root: 1.8
access list:
symbolic names:
keyword substitution: kv
total revisions: 8; selected revisions: 8
description:
This is the subtractor req_client
—————————-
revision 1.8 locked by: root;
date: 2015/08/04 07:09:48; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.7
date: 2015/08/04 07:02:15; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 06:59:10; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:56:05; author: root; state: Exp; lines: +5 -5
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:38:26; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:48; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:16; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
============================================================================RCS file: ./req_mul.c,v
Working file: ./req_mul.c
head: 1.8
branch:
locks: strict
root: 1.8
access list:
symbolic names:
keyword substitution: kv
total revisions: 8; selected revisions: 8
description:
This is the mul req_client
—————————-
revision 1.8 locked by: root;
date: 2015/08/04 07:09:49; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.7
date: 2015/08/04 07:07:32; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 06:59:11; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:56:06; author: root; state: Exp; lines: +4 -5
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:38:27; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:49; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:17; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================
=
RCS file: ./server.c,v
Working file: ./server.c
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4; selected revisions: 4
description:
—————————-
revision 1.4 locked by: root;
date: 2015/08/31 18:06:59; author: root; state: Exp; lines: +7 -0
Included comment
—————————-
revision 1.3
date: 2015/08/04 07:09:52; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:37:11; author: root; state: Exp; lines: +6 -6
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 18:34:43; author: root; state: Exp;
Initial revision
=============================================================================RCS file: ./proc_add.c,v
Working file: ./proc_add.c
head: 1.8
branch:
locks: strict
root: 1.8
access list:
symbolic names:
keyword substitution: kv
total revisions: 8; selected revisions: 8
description:
This is proc_client for adder
—————————-
revision 1.8 locked by: root;
date: 2015/08/31 18:06:54; author: root; state: Exp; lines: +3 -0
Included comment
—————————-
revision 1.7
date: 2015/08/04 07:09:49; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 07:07:33; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:56:06; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:18:14; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:49; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:18; author: root; state: Exp; lines: +2 -1
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================RCS file: ./proc_sub.c,v
Working file: ./proc_sub.c
head: 1.7
branch:
locks: strict
root: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7; selected revisions: 7
description:
This is the proc_client for subtractor
—————————-
revision 1.7 locked by: root;
date: 2015/08/04 07:09:50; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 07:07:33; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:56:07; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:18:15; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:50; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:18; author: root; state: Exp; lines: +2 -1
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================RCS file: ./proc_mul.c,v
Working file: ./proc_mul.c
head: 1.7
branch:
locks: strict
root: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7; selected revisions: 7
description:
This is the processing client for the multiplier
—————————-
revision 1.7 locked by: root;
date: 2015/08/04 07:09:51; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.6
date: 2015/08/04 07:07:33; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.5
date: 2015/08/04 06:56:08; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.4
date: 2015/08/03 18:18:16; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.3
date: 2015/08/03 18:14:50; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.2
date: 2015/08/03 18:12:19; author: root; state: Exp; lines: +2 -1
*** empty log message ***
—————————-
revision 1.1
date: 2015/08/03 17:53:18; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

Multiple Data Compression Technique

Multiple Data Compression is an iterative technique to compress the text data.

RCS file: ./header.h,v
Working file: ./header.h
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4; selected revisions: 4
description:
This is the header file
—————————-
revision 1.4 locked by: root;
date: 2015/10/29 15:19:42; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.3
date: 2015/10/29 14:38:28; author: root; state: Exp; lines: +8 -1
*** empty log message ***
—————————-
revision 1.2
date: 2015/10/29 14:29:02; author: root; state: Exp; lines: +2 -1
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: ./main.c,v
Working file: ./main.c
head: 1.3
branch:
locks: strict
root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
This is the main file
—————————-
revision 1.3 locked by: root;
date: 2015/10/31 16:15:42; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.2
date: 2015/10/29 14:29:04; author: root; state: Exp; lines: +11 -8
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:23:27; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: ./ma.c,v
Working file: ./ma.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
This file is to find the master array
—————————-
revision 1.2 locked by: root;
date: 2015/10/31 17:37:53; author: root; state: Exp; lines: +4 -3
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: ./mdc.c,v
Working file: ./mdc.c
head: 1.3
branch:
locks: strict
root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
This is the main file
—————————-
revision 1.3 locked by: root;
date: 2015/10/31 17:37:51; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.2
date: 2015/10/29 14:23:35; author: root; state: Exp; lines: +2 -25
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: ./cl.c,v
Working file: ./cl.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
This file is to find the codelength
—————————-
revision 1.1 locked by: root;
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: ./compress.c,v
Working file: ./compress.c
head: 1.16
branch:
locks: strict
root: 1.16
access list:
symbolic names:
keyword substitution: kv
total revisions: 16; selected revisions: 16
description:
This file is compress the file
—————————-
revision 1.16 locked by: root;
date: 2015/11/05 07:36:34; author: root; state: Exp; lines: +4 -4
*** empty log message ***
—————————-
revision 1.15
date: 2015/11/05 07:30:51; author: root; state: Exp; lines: +10 -10
*** empty log message ***
—————————-
revision 1.14
date: 2015/10/31 17:37:54; author: root; state: Exp; lines: +13 -0
*** empty log message ***
—————————-
revision 1.13
date: 2015/10/30 10:53:09; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.12
date: 2015/10/30 10:45:30; author: root; state: Exp; lines: +71 -11
*** empty log message ***
—————————-
revision 1.11
date: 2015/10/30 07:05:04; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.10
date: 2015/10/30 07:01:47; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.9
date: 2015/10/30 06:47:32; author: root; state: Exp; lines: +3 -0
*** empty log message ***
—————————-
revision 1.8
date: 2015/10/29 17:12:00; author: root; state: Exp; lines: +3 -0
*** empty log message ***
—————————-
revision 1.7
date: 2015/10/29 17:04:29; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.6
date: 2015/10/29 16:55:22; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.5
date: 2015/10/29 16:18:57; author: root; state: Exp; lines: +46 -0
*** empty log message ***
—————————-
revision 1.4
date: 2015/10/29 15:19:44; author: root; state: Exp; lines: +75 -21
*** empty log message ***
—————————-
revision 1.3
date: 2015/10/29 14:50:01; author: root; state: Exp; lines: +13 -0
*** empty log message ***
—————————-
revision 1.2
date: 2015/10/29 14:38:30; author: root; state: Exp; lines: +15 -2
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: ./decompress.c,v
Working file: ./decompress.c
head: 1.27
branch:
locks: strict
root: 1.27
access list:
symbolic names:
keyword substitution: kv
total revisions: 27; selected revisions: 27
description:
This file is to decompress
—————————-
revision 1.27 locked by: root;
date: 2015/11/05 07:45:47; author: root; state: Exp; lines: +8 -8
*** empty log message ***
—————————-
revision 1.26
date: 2015/11/05 07:36:35; author: root; state: Exp; lines: +10 -10
*** empty log message ***
—————————-
revision 1.25
date: 2015/11/05 07:33:46; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.24
date: 2015/11/05 07:30:53; author: root; state: Exp; lines: +14 -14
*** empty log message ***
—————————-
revision 1.23
date: 2015/10/31 17:37:54; author: root; state: Exp; lines: +5 -9
*** empty log message ***
—————————-
revision 1.22
date: 2015/10/30 14:53:55; author: root; state: Exp; lines: +5 -0
*** empty log message ***
—————————-
revision 1.21
date: 2015/10/30 14:52:43; author: root; state: Exp; lines: +4 -2
*** empty log message ***
—————————-
revision 1.20
date: 2015/10/30 14:51:23; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.19
date: 2015/10/30 14:49:39; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.18
date: 2015/10/30 14:48:48; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.17
date: 2015/10/30 14:46:45; author: root; state: Exp; lines: +2 -3
*** empty log message ***
—————————-
revision 1.16
date: 2015/10/30 10:45:31; author: root; state: Exp; lines: +47 -1
*** empty log message ***
—————————-
revision 1.15
date: 2015/10/29 17:18:49; author: root; state: Exp; lines: +8 -0
*** empty log message ***
—————————-
revision 1.14
date: 2015/10/29 17:14:50; author: root; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.13
date: 2015/10/29 17:14:30; author: root; state: Exp; lines: +0 -8
*** empty log message ***
—————————-
revision 1.12
date: 2015/10/29 17:13:12; author: root; state: Exp; lines: +9 -8
*** empty log message ***
—————————-
revision 1.11
date: 2015/10/29 17:12:01; author: root; state: Exp; lines: +8 -0
*** empty log message ***
—————————-
revision 1.10
date: 2015/10/29 16:59:58; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.9
date: 2015/10/29 16:55:23; author: root; state: Exp; lines: +38 -1
*** empty log message ***
—————————-
revision 1.8
date: 2015/10/29 15:35:17; author: root; state: Exp; lines: +1 -0
*** empty log message ***
—————————-
revision 1.7
date: 2015/10/29 15:34:15; author: root; state: Exp; lines: +0 -1
*** empty log message ***
—————————-
revision 1.6
date: 2015/10/29 15:33:58; author: root; state: Exp; lines: +0 -3
*** empty log message ***
—————————-
revision 1.5
date: 2015/10/29 15:32:47; author: root; state: Exp; lines: +2 -2
*** empty log message ***
—————————-
revision 1.4
date: 2015/10/29 15:32:19; author: root; state: Exp; lines: +61 -18
*** empty log message ***
—————————-
revision 1.3
date: 2015/10/29 14:50:02; author: root; state: Exp; lines: +19 -7
*** empty log message ***
—————————-
revision 1.2
date: 2015/10/29 14:38:31; author: root; state: Exp; lines: +25 -1
*** empty log message ***
—————————-
revision 1.1
date: 2015/10/29 14:00:38; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Data Structures with C, Project 2: Multiple Data Compression and Encryption | Leave a comment

Write a program to find particular no. is power of two or not?

CODE:

#include<stdio.h>
int main()
{
int n;
printf(“Enter a value\n”);
scanf(“%d”,&n);
if((n &(n-1))==0)
printf(“no. is power of 2\n”);
else
printf(“no. is not power of 2\n”);
return 0;
}

Posted in Data Structures with C | Leave a comment

Write a program to reverse a number?

CODE:

#include<stdio.h>
int main()
{
int n,r=0,num;
printf(“Enter a number:\n”);
scanf(“%d”,&n);
num=n;
while(n!=0)
{
r=r*10;
r=r+n%10;
n=n/10;
}
printf(“Reverse number is %d\n”,r);
if(num==r)
printf(“Palindrome number\n”);
else
printf(“Not a Palindrome\n”);
return 0;
}

Posted in Data Structures with C | Leave a comment

Write a program to print Diamond Pattern?

CODE:

#include<stdio.h>
int main()
{
int i,j,k,n,space,temp;
printf(“enter value of n\n”);
scanf(“%d”,&n);
temp=n;
for(i=1;i<=n;i++)
{
for(j=i;j<n;j++)
{
printf(” “);
}
for(k=1;k<(2*i);k++)
{
printf(“*”);
}
printf(“\n”);
}
temp=1;
for(i=n-1;i>=1;i–)
{
for(j=1;j<=temp;j++)
{
printf(” “);
}
temp++;
for(k=1;k<(i*2);k++)
{
printf(“*”);
}
printf(“\n”);
}
}

 

Posted in Data Structures with C | Leave a comment

Write a program to find the range of data types?

CODE:

#include<stdio.h>
#include<limits.h>
#include<float.h>
int main()
{
printf(“Range of integer value:%d to %d \n”,INT_MIN,INT_MAX);
printf(“Range of char value:%d to %d \n”,CHAR_MIN,CHAR_MAX);
printf(“Range of float value:%e to %e \n”,FLT_MIN,FLT_MAX);
printf(“Range of double value:%e to %e \n”,DBL_MIN,DBL_MAX);
printf(“Range of long double value:%e to %e \n”,LDBL_MIN,LDBL_MAX);
//printf(“Range of integer value:%d to %d \n”,LINT_MIN,LINT_MAX);
}

Posted in Data Structures with C | Leave a comment

Write a program to find LCM and HCF of three number?

CODE:

#include<stdio.h>
int main()
{
int a,b,c,x,y,z,lcm,hcf,r,lcm1;
printf(“Enter three number\n”);
scanf(“%d%d%d”,&x,&y,&z);
a=x;
b=y;
c=z;
while(x!=0)
{
r=y%x;
y=x;
x=r;
}
lcm=(a*b)/y;
while(y!=0)
{
r=z%y;
z=y;
y=r;
}
hcf=z;
lcm1=(lcm*c)/hcf;
printf(“LCM:%d”,lcm1);
printf(“HCF:%d”,hcf);
return 0;
}

Posted in Data Structures with C | Leave a comment

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));
}
printf(“\n”);
}
}

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 ();

int main()
{
system(“clear”);
struct distance d1,d2,d3,d4;
d1=input();
d2=input();
d3=addlist(d1,d2);
d4=convert(d3);
display(d1,d2,d3,d4);
return 0;
}

struct distance input ()
{
struct distance d;
printf(“Enter distance in feet\n”);
scanf(“%d”,&d.feet);
printf(“Enter distance in Inches\n”);
scanf(“%f”,&d.inch);
return d;
}

struct distance addlist(struct distance d1 ,struct distance d2)
{
struct distance d;
d.feet=d1.feet+d2.feet;
d.inch=d1.inch+d2.inch;
if(d.inch >11)
{
d.feet++;
d.inch=d.inch-12;
}
return d;
}
struct distance convert(struct distance d3)
{
struct distance d;
d.meter=d3.feet*0.30;
d.cm=d3.inch*2.54;
return d;
}

struct distance display(struct distance d1,struct distance d2,struct distance d3,struct distance d4)
{
printf(“feet: %d + %d =%d \n inch: %f + %f =%f\n”,d1.feet,d2.feet,d3.feet,d1.inch,d2.inch,d3.inch);
printf(“feet:%d inch:%f=%dm%fcm\n”,d3.feet,d3.inch,d4.meter,d4.cm);
}

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];
}
}
}
if(flag == 0)
{
printf(“Element Not found\n”);
}
printf(“New Array Created Is \n”);
for(i=0;i<n;i++)
{
printf(“Array[%d]=%d\n”,i,a[i]);
}
}

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++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<m-1-i;j++)
{
if(b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
printf(“Elements of Array1\n”);
for(i=0;i<n;i++)
{
printf(“a[%d]=%d\n”,i,a[i]);
}
printf(“Elements of Array2\n”);
for(i=0;i<m;i++)
{
printf(“b[%d]=%d\n”,i,b[i]);
}
j=0;
k=0;
for(i=0;i<o;i++)
{
if(a[j]<=b[k])
{
c[i]=a[j];
j++;
}
else
{
c[i]=b[k];
k++;
}
}
printf(“Merged array is :\n”);
for(i=0;i<o;i++)
{
printf(“c[%d]=%d\n”,i,c[i]);
}
}

Posted in Data Structures with C | Leave a comment