Saturday, April 17, 2021

Some awesome C Programming PDF books can be downloaded!

1. C The Complete Reference 4th Edition by Herbert Schildt. >>Download

2. C Language Tutorial by Gordon Dodrill, Coronado Enterprises.>>Download

3. TURBO C: Users Guide IBM Version PC, AT, XT & True Compatibles.>>Download

4. The C Programming Language 2nd Edition book by Brian Kernighan and Dennis Ritchie.>>Download

5. Expert C Programming Deep C Secrets By Peter van der Linden.>>Download

6. Problem Solving in Data Structures and Algorithms Using C First Edition by Hemant Jain.>>Download

7. Learn to Code with C Program with the World most Popular Language on your Raspberry Pi written by Simon Long.>>Download

8. C Programming-Absolute Beginner guide by Greg Perry and Dean Miller.>>Download 

Tuesday, April 13, 2021

20.59. Write a program that swaps two numbers.

#include<stdio.h>
#inctude<conio.h>
void swap(int *a, int *b)
{
int temp;
tamp=*a;
*a=*b;
*b=temp;
}
void main ()
{
int a,b;
clrscr();
printf("a=   ") ;
scanf("%d", &a);
printf("b=   ");
scanf("%d", &b);
swap (&a, &b) ;
printf("After swap:  \n");
printf("a=  %d\n", a);
printf("b=  %d\n", b);
getch ();
}

20.58. Write a program that create, insert, and delete a two-way link list.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
int info;
struct node *next, *prev;
};
strict node *makenode (int n)
{
struct node t;
t=(struct node *)alloc(sizeof (struct node));
t->info=r;
t->next-NULL;
t->prev=NULL;
return t;
}
void makelist (struct node *list)
{
int i,n,num;
printf("How many node: "):
scanf ("%d", &n);
for (i=1; i<-n; i++)
{
scanf ("%d", &num);
list->next=makanode(num);
list->next->prev=list;
list=list->next;
}
}
void print list (struct node *list)
{
printf ("\list contains: \n");
while(list->rext!=NULL)
{
printf("%5d",list-next->info);
list=list->next;
}
}
int countlist (struct nede *list)
{
int count=0;
while (list->next!-NULL)
{
count++;
list=list->next;
}
return count;
}
void insert first (struct node *list)
{
int n;
struct node *t;
printf ("Enter any number to insert first: ";
scanf("%d", &n);
t=makenode(n);
list->next->prev=t;
t->prev=list;
t->next=list->next;
list->next=t;
}
void deletefirst (struct node *list)
{
struct node *t;
t=list->next->next;
free (list->next);
t->prev=list;
list->next=t;
}
void insert middle (struct node *list)
{
int i,n,count, p;
struct node *t;
count countlist(list);
printf("Enter any position to insert: ") ;
scanf ("%d", &p);
If (p<1 || p>count+1)
printf("Insert is impossible.");
else
{
for (i=1; i<p; i++) 
list=list->next;
printf("Enter any number to insert middle:”);
scanf ("%d", &n);
t=makenode(n);
list->next->prev=t;
t->prev=list;
t->next=list->next;
list->next=t;
}
}
void deletemiddle (struct node list)
{
struct node *t; 
int count, i,p;
count count list (list);
printf("Enter any position to delete middle: ");
scanf("%d", &p);
If (p<1 || p>count)
printf("Delete is impossible.");
else
{
for (i=1; i<p; i++)
list=list->next;
t=list->next->ext;
free list->next);
t->prev=list;
list->next=t;
}
}
void insertlast (struct node *list)
{
int n;
struct node *t;
printf("Enter any number to insert last: ";
scanf ("%d",&n);
t=makenode (n):
while (list->next!=NULL)
list-list->rext;
t->prev=list;
list->next=t;
}
void deletelast(struct node list)} 1
{
while (list->next->next!=NULL)
list=list->next;
free (list->next);
list->next=NULL;
}
void main ()
{
int n, choice;
struct node *list;
clrscr();
list=(struct node *)malloc(sizeof (struct nod makelist (1ist);
do
{
clrscr ():
print list (list);
printf("\r.Enter your cliocie from 1 to 7.");
printf("\r1. Insert First.");
printf("\r2. Insert Middle.");
printf("\r3. Insert Last.");
printf("\r4. Delete First.");
printf("\r5. Delete Middle.");
printf("\r6. Delete Last.");
printf("\r7. Exit\n");
scanf ("%d", &choice); 
switch (chcice)
{
case 1:
insertfirst (list);
break;
case 2:
insertmiddle (list);
break:
case 3:
insertlast (list);
break;
case 4:
deletefirst (list):
break;
case 5:
deletemiddle (list);
break;
case 6:
deletelist (list);
break:
case 7:
printf("\nThe program is now exit.");
printf("\nPress any key to continue”);
break;
default:
printf("\nYour choice out of range. ");
printf("\nPlease try again.");
print list (list);
getch ();
}
while(choice! =7);
}
 

 

Monday, April 12, 2021

20.57. Write a program that create, insert, and delete a one-way link list.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
int info;
struct node *next;
};
struct node *makenode (int n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list
{
int i, n, rum;
printf("How many node: "); 
scanf ("%d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%d",&num);
list->next=>namenode(num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%5d",list->next->info);
list=list->next;
}
}
int countlist(struct node *list)
{
int count=0;
while(list->next!=NULL)
{
count++;
list=list->next;
}
return count;
}
void insertfirst (struct node *list)
{
int n;
struct node *t;
printf("\nEnter any number to insert first: ");
scanf ("%d", &n.);
t=makenocie (n);
t->next-list->next;
list->next=3t;
}
void deletefirst (struct node list)
{
struct node *t;
t=list->next->next;
free (list->next); 
list-next%3Dt%;
}
Void insertlast (st cuct node list)
{
int n;
struct node *t;
printf("\nEnter any number to insert last: ");
scanf ("%d", &r):
while (list->next!=NULL) List=list->next;
1ist->next-makenode (n);
}
void deletelast (struct node list)
{
while (list->next->next!-NULL) 
list=list->next; 
free(list->next);
list->next = NULL;
}
void insertmiddle (struct node *list)
{
int n, 
count,i,p; 
struct node t;
count->count list (list);
printf("\nEnter any position to insert: ");
scanf("%d", &p); 
if(p<1 11 p>count+1)
printf("Insert is impossible";
else
{
for (i=1; i<p; i++) 
1ist=list->next;
printf("after any number to insert middle”);
scanf ("%d", &n); 
t=make node (n);
t->next->list->next;
list->next=t;
}
}
void delete middle (struct node *list)
{
int count, i,p;
struct node *t;
Count=countiist (1ist);
printf("\nEnter any position to delete: ");
scanf("%d", &p); 
if (p<1 || p>count)
printf("Celete is impossible"},
alse
{
for (i-1; i<p; 1++)
1ist=list->next;
t=list->next->next;
free (list->next);
list->next=t;
}
}
void main()
{
int n, choice;
struct node *list:
int=(struct node *) malloc(sizeof (struct node));
makelist (list):
do
{
clrscr ():
print list (list);
printf("\r.Enter your cliocie from 1 to 7.");
printf("\r1. Insert First.");
printf("\r2. Insert Middle.");
printf("\r3. Insert Last.");
printf("\r4. Delete First.");
printf("\r5. Delete Middle.");
printf("\r6. Delete Last.");
printf("\r7. Exit\n");
scanf ("%d", &choice); 
switch (chcice)
{
case 1:
insertfirst (list);
break;
case 2:
insertmiddle (list);
break:
case 3:
insertlast (list);
break;
case 4:
deletefirst (list):
break;
case 5:
deletemiddle (list);
break;
case 6:
deletelist (list);
break:
case 7:
printf("\nThe program is now exit.");
printf("\nPress any key to continue”);
break;
default:
printf("\nYour choice out of range. ");
printf("\nPlease try again.");
print list (list);
getch ();
}
while(choice! =7);
}




20.56. Write a program that create a link list to store some double numbers.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
double info;
struct node *next;
};
struct node *makenode (
double n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list)
{
int i, n;
double num;
printf("How many node: "); 
scanf ("%d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%lf",&num);
list->next namenode (num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%lf",list->next->info);
list=list->next;
}
}
void main()
{
struct node *start;
start=(struct node *)malloc(sizeof (struct node));,
clrscr();
make list (start);
printlist (start);
getch ();
}
 

20.55. Write a program that create a link list to store some long numbers.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
long info;
struct node *next;
};
struct node *makenode (
long n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list)
{
int i, n;
long num;
printf("How many node: "); 
scanf ("%d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%ld",&num);
list->next namenode (num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%ld",list->next->info);
list=list->next;
}
}
void main()
{
struct node *start;
start=(struct node *)malloc(sizeof (struct node));,
clrscr();
make list (start);
printlist (start);
getch ();
}
 

20.54. Write a program that create a link list to store some character.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
char info;
struct node *next;
};
struct node *makenode (
char n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list
{
int i, n;
char num;
printf("How many node: "); 
scanf ("d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%d",&num);
list->next namenode (num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%c",list->next->info);
list=list->next;
}
}
void main()
{
struct node *start;
start=(struct node *)malloc(sizeof (struct node));,
clrscr();
make list (start);
printlist (start);
getch ();
}
 

20.53. Write a program that create a link list to store some integer numbers.

#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
int info;
struct node *next;
};
struct node *makenode (int n)
{
struct node *t;
t= (struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list
{
int i, n, rum;
printf("How many node: "); scanf ("d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%d",&num);
list->next namenode (num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%5d",list->next->info);
list=list->next;
}
}
void main()
{
struct node *start;
start= (struct node *)malloc(sizeof (struct node));,
clrscr();
make list (start);
printlist (start);
getch ();
}
 

Saturday, April 10, 2021

20.52. Write a program that read and display some students name, roll and mark.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>  
struct student 
{
char name [30] 
int roll,mark;
};
void main()
{
struct student *a;
int i,j,n;
printf("\How many student: ");
scanf("%d, &n);
a=(struct *)malloc(sizeof(struct student)*n);
for(i=0;i<n;i++)
{
printf("Enter Name: ");
scanf("%s,&(a+i)->name);
printf("Enter Roll: ");
scanf("%s,&(a+i)->roll);
printf("Enter Mark: ");
scanf("%s,&(a+i)->mark);
}
printf("\name Roll Mark");
printf("\----- ----- -----");
for(i=0;i<n;i++)
printf("\n%-10s %4d %4d", (a+i)->name, (a+i)->roll, (a+i)->mark); 
getch();
}

20.51. Write a program that read and display any students name, roll, mark.

#include<stdio.h>
#include conio.h>
#include<stdlib.h>  
struct student 
{
char name [30] 
int roll,mark;
};
void main()
{
struct student *a, temp;
int i,j,n;
a=(struct *)malloc(sizeof(struct student));
printf("Enter Name: ");
scanf("%s,a->name);
printf("Enter Roll: ");
scanf("%s,a->roll);
printf("Enter Mark: ");
scanf("%s,a->mark);
}
printf("Name: %s Roll: %d  Mark: %d",a->name,a->roll,a->mark); 
getch();
}