0% found this document useful (0 votes)
35 views

C Programs

The document contains the source code for a library management system written in C. It allows the user to add books, search for books, and sort the books by name or author name. Structures are used to store book details and functions are used to perform the various operations. [SUMMARY

Uploaded by

Gopi Chandu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

C Programs

The document contains the source code for a library management system written in C. It allows the user to add books, search for books, and sort the books by name or author name. Structures are used to store book details and functions are used to perform the various operations. [SUMMARY

Uploaded by

Gopi Chandu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

c   

  c   
 


 
 
 


  cc 

   !
"
 #$
%
  &'(
 &'&)'*+'(
#$(
, #-   . "/-$(
 #-0
-'1&$(
&+#&2$34(
33 , #-0-'#&$$(
&)+&2&(
+(
*+(
#+)(5#$cc(+6)$
%
 + #&)2#7$$3#2#7$$(
* + *6(
8
, #-9 :; 0-'*$(
#$(
8

c   
  c   
 


 
 
 


  cc 

   !
"
 #$
%
  &'(
 &'&)'*+'(
#$(
, #-   . "/-$(
 #-0
-'1&$(
&+#&2$34(

33 , #-0-'#&$$(
&)+&2&(
+(
*+(
#+)(5#$cc(+6)$
%
 + #&)2#7$$3#2#7$$(
* + *6(
8
, #-9 :; 0-'*$(
#$(
8

c   &,   "


#include<stdio.h>
#include<conio.h>
void main()
{
double term=1,expo=1;
float x;
int i;
clrscr();
printf("Enter the exp value of x: ");
scanf("%f",&x);
for(i=1;term>=0.00001;i++)
{
term *= x/i;
expo+=term;
}
printf("\Our Exp = %f %f\n",x,expo);
getch();
}

c       


 


 
 
  # $(
"
 #$
%
  '5+'(
#$(
, #-   : "/-$(
 #-0
-'1$(

;#$
%, #-9 9   < ," 59 -$(
, #-  : "/-$(
 #-0
-'1$(
8
5+#$(
, #-0
-'5$(
#$(
8
  #  &$
%
#&++$
%
 #$(
8

%
 ##&$2##&7$$$(
8
8

c   5      


 


 
 
  5# $(
"
 #$
%
  '5''(
#$(
, #-   : "-$(
 #-0
-'1$(
#+((66$
%
, #-9 0
-'5#$$(
8
#$(
8
  5#  &$
%
#&++$
 #$(
#&+$
%
 #$(

8

%
 #5#&7$6#5#&7)$$$(
8
8

c     = 


#include<stdio.h>
#include<conio.h>
void main()
{
int i,c=0;
char a[50];
clrscr();
printf("OUTPUT\n");
printf("------");
printf("\n\n");
printf("Please Enter a String:\n");
printf("*********************");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
c=c+1;
}
printf("\n\n");
printf("Length Of The Given String is=%d\n",c);
printf("*****************************");
getch();
}

c   =5< , 


#include<stdio.h>
#include<conio.h>
int i=0;
void add();
void search();
void sort();
void sorta();
struct book
{
char bookname[50];
char author[50];
double price;

int nocopy;
}book[50];
void main()
{
int ch;
while(1)
{
clrscr();
printf("********************");
printf("\nLIBRARY MANAGEMENT");
printf("\n******************");
printf("\n1-ADD TO LIBRARY");
printf("\n2-SEARCH A BOOK");
printf("\n3-SORT BY BOOK NAME");
printf("\n4-SORT BY AUTHOR NAME");
printf("\n5-EXIT");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
break;
case 2: search();
break;
case 3: sort();
break;
case 4: sorta();
break;
case 5: exit(0);
default: puts("Please enter 1-5 only");
getch();
}
}
}
void add()
{
printf("\n\nADD TO LIBRARY");
printf("\nEnter the Bookname: ");
fflush(stdin);
gets(book[i].bookname);
printf("\nEnter the Author name: ");
fflush(stdin);
gets(book[i].author);
printf("\nEnter the Price of the Book: ");
scanf("%ld",&book[i].price);
printf("\nEnter no of copies : ");
scanf("%d",&book[i].nocopy);
printf("STORED");

printf("\nBOOK NAME: %s",book[i].bookname);


printf("\nAUTHOR : %s",book[i].author);
printf("\nPRICE : %d",book[i].price);
printf("\nNO OF COPIES: %d",book[i].nocopy);
i++;
getch();
}
void search()
{
int f=0,y,j,x;
char bookn[50],authorname[50];
printf("\n Enter the Book Name: ");
fflush(stdin);
gets(bookn);
printf("\n Enter the Author Name: ");
fflush(stdin);
gets(authorname);
printf("\nThe Given Search");
printf("\nThe Book Name is: %s",bookn);
printf("\nThe Author Name is : %s",authorname);
for(j=0;j<i;j++)
{
x= strcmp(book[j].bookname,bookn);
y=strcmp(book[j].author,authorname);
if(x==0&&y==0)
{
printf("\nBOOK IS FOUND");
getch();
f=1;
}
}
if(f==0)
{
printf("\nBOOK NOT FOUND");
getch();
}
getch();
}
void sort()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].bookname,book[k+1].bookname));
if(x>0)

{
strcpy(t,book[k].bookname);
strcpy(book[k].bookname ,book[k+1].bookname);
strcpy(book[k+1].bookname, t);
}
}
}
printf("\nSORTED BY BOOK NAME");
for(j=0;j<i;j++)
{
printf("\nThe BookName is:%s - %s",book[j].bookname,book[j].author);
}
getch();
}
void sorta()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].author,book[k+1].author));
if(x>0)
{
strcpy(t,book[k].author);
strcpy(book[k].author ,book[k+1].author);
strcpy(book[k+1].author, t);
}
}
}
printf("\nSORTED BY AUTHOR NAME");
for(j=0;j<i;j++)
{
printf("\nThe AUTHOR NAME is:%s - %s",book[j].author,book[j].bookname);
}
getch();
}

c > ?>@ A >  c= >:?=


#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j,num,x=1;
clrscr();

printf("Please Enter the Number :");


scanf("%d",&num);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Pascal triangle is\n");
printf("**********************\n");
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
if(j==1)
{
x=1;
printf("%d",x);
}
else
{
x=(x*(i-j+1)/(j-1));
printf("%d",x);
}
}
printf("\n");
}
getch();
}

c    :5 ?  


#include<stdio.h>
#include<conio.h>
void main()
{
int n,j,a=0,i;
clrscr();
printf(" Please Enter a number :");
scanf("%d",&n);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Prime Number series is\n");
printf("**************************");
for(j=1;j<=n;j++)
{
for(i=2;i<j;i++)

{
if(j%i==0)
{
a=1;
goto x;
}
}
if((a==0)&&(j!=1))
{
printf("\n%d",j);
}
x:
a=0;
}
getch();
}

You might also like