EmbLogic's Blog

To Understand Double Pointer Concept

#include<stdio.h>
int main()
{
int value=77,num=99;
int *pv=&value,*pn=&num;
int **ppi;
ppi=&pv;
printf(“**ppi=%d\n”,**ppi);
ppi=&pn;
printf(“**ppi=%d\n”,**ppi);
system(“pause”);
}
 

in this program we  use two pointer as shown in program . In this first two value are stored in two variable after that we pointed address of both variable using one pointer as shown in program and  address of the first pointer are stored in the other variable and as a second pointer we use second variable and if we print the second pointer then its shows the value as **ppi=77

Posted in Uncategorized | Leave a comment

C program to insert an element in an array of size 10

#include
int main()
{
int n,i,a[10]={1,2,3};
printf(“enter element you want to add:”);
scanf(“%d”,&n);
for(i=9;i>=0;i–)
{
a[i]=a[i-1];
if(i==0)
a[i]=n;
// printf(“a[%d]=%d\n”,i,a[i]);
}
printf(“After adding element:\n”);
for(i=0;i<9;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
}

Posted in Data Structures with C | Leave a comment

Program of Addition of Two array an Answer storing in Third Array

#include<stdio.h>
int main()
{
int a[100],b[100],c[100],i,n;
printf(“enter element of array :”);
scanf(“%d”,&n);
printf(“Enter element of A:\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter element of A:\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
}
for(i=0;i<n;i++)
{
c[i]=a[i]+b[i];
}
for(i=0;i<n;i++)
{
printf(“a[%d] + b[%d]=c[%d]\n”,a[i],b[i],c[i]);
}

}

Posted in Uncategorized | Leave a comment

Program To Print Array index with its Element

#include<stdio.h>
int main()
{
int a[100],i,n;
printf(“enter element of array :\t”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<n;i++)
{
printf(“a[%d]=%d\n”,i,a[i]);
}
}

Posted in Uncategorized | Leave a comment

Finding Average of an array

#include<stdio.h>
int main()
{
int  a[100],n,i;
float Avg=0,sum=0;
printf(“enter Numbre of  array :\t”);
scanf(“%d”,&n);
printf(“Enter the element of array\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
sum=sum+a[i];
}
Avg=sum/n;
printf(“Avg = %f\n”,Avg);
return 0;
}

Posted in Uncategorized | Leave a comment

Finding the largest number in an array

#include<stdio.h>
int main()
{
int a[100],n,i,j;
printf(“enter the value of array:”);
scanf(“%d”,&n);
printf(“enter the value :\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
j=a[0];
for(i=1;i<n;i++)
{
if(j<a[i])
j=a[i];
else
j=j;
}

printf(“Largest element of array is :%d\n”,j);

}

Posted in Uncategorized | Leave a comment

C program for bubble sorting

#include
int main()
{
int i,j,k,a[100],n;
printf(“Enter size of array:”);
scanf(“%d”,&n);
printf(“Enter element of an array:”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;ja[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
printf(“Array after bubble sorting:\n”);
for(i=0;i<n;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
}

Posted in Data Structures with C | Leave a comment

inserting the element in array

#include<stdio.h>
2 main()
3 {
4     int i,j,k,l,m,A,v;
5     printf(“\nsize”);
6     scanf(“%d”,&k);
7     char x;
8
9     int a[k];
10
11     for(i=0;i<k;i++)
12     {
13         scanf(“%d”,&a[i]);
14     }
15
16     while(1){
17     getchar();
18     printf(“\npress i to insetre tyhe array”);
19     scanf(“%c”,&x);
20
21     if(x==’i’)
22     {
23         printf(“\naddress:- “);
24         scanf(“%d”,&A);
25
26         printf(“\nvalue:- “);
27         scanf(“%d”,&v);
28
29         for(j=0;j<=k-A;j++)
30         {
31             a[A+j++]=a[A+j];
32             a[A]=v;
33         }
34     }
35
36    for(i=0;i<k;i++)
37    {
38         printf(“\na[%d] = %d”,i,a[i]);
39    }}
40 }

Posted in Uncategorized | Leave a comment

a prog. to insert some more elements in an array…

1 #include<stdio.h>
2 void main()
3 {
4                 int i,j,n,n1,n2;
5
6
7         printf(“\n\nenter the number of values u will enter : “);
8
9 scanf(“%d”,&n1);
10
11                int a[n1];
12
13         printf(“\nnow enter values of elements : \n”);
14
15
16                         for(i=0;i<n1;i++)
17                         {
18                                 scanf(“%d”,&a[i]);
19                         }
20
21         printf(“\nnow enter the number of value u want to insert in an array :”);
22
23 scanf(“%d”,&n2);
24
25                 int b[n2];
26
27
28         printf(“\nnow enter the elements u want to insert in an array : \n”);
29
30
31                         for(i=0;i<n2;i++)
32                         {
33                                 scanf(“%d”,&b[i]);
34                         }
35
36
37
38                         n=n1+n2;
39
40                           int c[n];
41
42
43                                 for(i=0;i<n1;i++)
44                                 {
45                                         c[i]=a[i];
46                                 }
47
48
49
50
51
52                                                 for(j=n-1;j>1;j–)
53                                                 {
54                                                         c[j]=c[j-n2];
55
56                                                 }
57
58
59
60         for(i=0;i<n2;i++)
61         {
62                 c[i]=b[i];
63         }
64
65                                 printf(“\nnow the array is : \n”);
66
67
68                 for(i=0;i<n;i++)
69                 {
70                         printf(“%d\n”,c[i]);
71                 }
72
73
74 }

Posted in Data Structures with C | Leave a comment

using bubble sorting a prog to make elements in accending order….

#include<stdio.h>
int main()
{
int i,j,b,k,n,l;

printf(“\n\nenter the number of values u will enter : “);
scanf(“%d”,&n);

int a[n];

printf(“\nnow enter the elements : \n”);

for(l=0;l<n;l++)
{
scanf(“%d”,&a[l]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
b=a[j];
a[j]=a[j+1];
a[j+1]=b;
}
}
}
for(k=0;k<n;k++)
{
printf(“\n%d”,a[k]);
}
}

Posted in Data Structures with C | Leave a comment

Link list logfile. Batch 06.01.14

LINK LIST creation, traversal, insertion(all options) and deletion(all options) completed.
RCS file: ll.c,v
Working file: ll.c
head: 1.7
branch:
locks: strict
root: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7;    selected revisions: 7
description:
SINGLY LINKED LIST
—————————-
revision 1.7    locked by: root;
date: 2014/07/06 14:31:05;  author: root;  state: Exp;  lines: +83 -16
delete_nth() and delete_key() functions implemented.
minor chnages in printf statements.
—————————-
revision 1.6
date: 2014/07/06 13:12:56;  author: root;  state: Exp;  lines: +44 -8
Implemented delete_end().
Added “deletion node possible” alert in delete_beg().
—————————-
revision 1.5
date: 2014/07/06 12:47:08;  author: root;  state: Exp;  lines: +52 -3
Implemented delete_beg().
—————————-
revision 1.4
date: 2014/07/04 18:26:28;  author: root;  state: Exp;  lines: +48 -10
Implemented insert_key(); i.e. a function to insert node after a key value location.
Also entered condition checking in insert_nth().
—————————-
revision 1.3
date: 2014/07/04 16:59:48;  author: root;  state: Exp;  lines: +84 -39
Implemented function to insert node at the beginning of link list and also a function to insert after nth node.
—————————-
revision 1.2
date: 2014/07/04 07:32:04;  author: root;  state: Exp;  lines: +1 -1
creation of link list, insertion at beginning and traversal have been implemented.
—————————-
revision 1.1
date: 2014/07/04 07:16:00;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Data Structures with C | Leave a comment

C program to compute area of triangle and square

#include
int main()
{
int area,triangle,side,base,height;
char ch;
printf(“Enter s for area and t for triangle:”);
scanf(“%c”,&ch);
switch(ch)
{
case ‘s’:
printf(“Enter side:”);
scanf(“%d”,&side);
area=side*side;
printf(“Area of square = %dm^2\n”,area);
break;
case ‘t’:
printf(“Enter base and hight:”);
scanf(“%d%d”,&base,&height);
area=(base*height)/2;
printf(“Area of triangle =%dm^2\n”,area);
}

}

Posted in Data Structures with C | Leave a comment

client server communication using pipe and signal

—in this program i’ve used the pipe for communication between server and three client.while single pipe for commmunication between processes and server.
for synchronisation i’ve used signal handler.signal(SIGUSR1,ouch).
—–program for server——

RCS file: ./server.c,v
Working file: ./server.c
head: 1.5
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 5; selected revisions: 5
description:
working for second client
created a pipe an
for communication between server and client2
—————————-
revision 1.5
date: 2014/07/06 12:05:00; author: root; state: Exp; lines: +110 -57
the server used three pipe for communication between three client
and single pipe for communication between process and server
for sync i’ve used signal sigusr
—————————-
revision 1.4
date: 2014/07/05 08:35:03; author: root; state: Exp; lines: +45 -7
make a new pipe for client3
recieve the data from client3 and proceed it to process 3
the process3 use the common pipe for all the three process
for sync i’ve used sleep
—————————-
revision 1.3
date: 2014/07/05 04:02:23; author: root; state: Exp; lines: +26 -5
in server for the client_2 i add a pipe between the client2 and server
by using the previous pipe which is between process1 and server
i used data communication between server and process2
to sync i used sleep as per requirement
—————————-
revision 1.2
date: 2014/07/04 18:58:33; author: root; state: Exp; lines: +7 -4
creating new pipe for process2
—————————-
revision 1.1
date: 2014/07/04 17:21:57; author: root; state: Exp;
Initial revision
=============================================================================
———–program for client—————–

RCS file: client1.c,v
Working file: client1.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
in client i’ve used if else condition
in the if condition it compare with the flag which has sent by server
for client1 i’ve sent message “client1″ to client when the if condition true then the client
receive the output
in else condition the client write the data to server
for sync i’ve used signal
—————————-
revision 1.1 locked by: root;
date: 2014/07/06 12:36:43; author: root; state: Exp;
Initial revision
============================================================================

***************process——————
RCS file: process1.c,v
Working file: process1.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
—————————-
revision 1.1 locked by: root;
date: 2014/07/06 13:03:08; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Write a c program to add two array of size 10 and store the sum into third array

#include
int main()
{
int i,a[10],b[10],c[10];
printf(“Enter the element of array1:\n”);
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element of array2:\n");
for(i=0;i<10;i++)
{
scanf("%d",&b[i]);
}
printf("Element of array3 are:\n");
for(i=0;i<10;i++)
{
c[i]= a[i]+b[i];
printf("a[%d]+b[%d]=%d\n",i,i,c[i]);
}
}

Posted in Data Structures with C | Leave a comment

C program for digital clock

#include

int main()
{
int sec=0,min=0,hour=0,i,j;
while(1)
{

if(sec>59)
{
min++;
sec=0;
}
if(min>59)
{
hour++;
min=0;
}
if(hour>23)
{
hour=0;
min=0;
sec=0;
}
sleep(1);
sec=sec+1;
system(“clear”);
printf(“\t\t%d:%d:%d\n”,hour,min,sec);

}
}

Posted in Data Structures with C | Leave a comment