Sunday, January 13, 2019

Write a menu driven program that depicts the working of a library.


Write a menu driven program that depicts the working of a library. The menu options should be:
(a) Add book Information
(b) Display book information
(c) List all books of given author
(d) List the title of specified book
(e) List the count of books in the library
(f) List the books in the order of accession number
(g) Exit

Create a structure called library to hold accession number, title of the book, author name, price of the book, and flag indicating whether book is issued or not.
PROGRAM



#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void abk();
void dbk();
void aabk();
void tbk();
void nbk();
void lbk();
void ebk();



struct library{
int accession,cost,n;
char tittle[20],author[20],name[20],flag[5];
}b[10];
int i=0;

int main()
{
char choice,g;
while(i>=0)
{

printf("\nif you want to Add book information , Then enter A or a ");
printf("\nif you want to display book information ,then enter B or b");
printf("\nif you want to know Author books,then enter C or c");
printf("\nif you want to list the tittle of the specified book,then enter D or d");
printf("\nif you want to know number of the books,then enter E or e");
printf("\nif you want to List books in the order of accession number ,then enter F or f");
printf("\nIf you want to exit,then enter G or g");
printf("\nIf you want to clear the screen,Then enter H or h");

printf("\nEnter your choice:");
scanf("%c",&choice);

fflush(stdin);
    
  
    switch(choice)
{
case 'a':  abk(); break;
case 'b': dbk(); break; 
case 'c': aabk();break;
case 'd': tbk(); break;
case 'e': nbk(); break;
case 'f': lbk(); break;
case 'A':  abk(); break;
case 'B': dbk(); break; 
case 'C': aabk();break;
case 'D': tbk(); break;
case 'E': nbk(); break;
case 'F': lbk(); break;
   case 'g' :exit(5); break;
      case 'G' :exit(5); break;
  case 'h' :system("cls"); break;   // clear output screen
  case 'H' :system("cls"); break; 
  default :printf("\nThere is no selection for '%c'",choice);
  
     
}
}
}

//ADDING INFORMATON

void abk()
{
printf("\nEnter accession number:");
scanf("%d",&b[i].accession);
fflush(stdin);
//(fflsh(stdin):If entered ouput is a null pointer, the fflush function will flush all entered specific output with unwritten data in the buffer)
printf("Enter Book name:");
gets(b[i].tittle);
fflush(stdin);
printf("Enter author name:");
gets(b[i].author);
fflush(stdin);
printf("Enter book price:");
scanf("%d",&b[i].cost);
fflush(stdin);

printf("BOOK ISSUMENT\t(yes or no):");
gets(b[i].flag);
fflush(stdin);
i++;
}


//DISPLAYING INFORMATION
void dbk()
{
int j;
char str[3]={'y','e','s'};
for(j=0;j<i;j++)
{
printf("\naccession number is %d\n",b[j].accession);
puts(b[j].tittle);
puts(b[j].author);
printf("book price is :%d",b[j].cost);

  if(strcmp(b[j].flag,str)==0)
  {
  printf("\n issued");
  }
  else
  {
  printf("\n not issued");
  }

}
}



//AUTHOR BOOK INFORMATION

void aabk()
{
int j;
char a2[20];
printf("\nEnter author name :");
gets(a2);
fflush(stdin);
for(j=0;j<i;j++)
{
if(strcmp(b[j].author,a2)==0)
{
printf("\naccession number is %d\n",b[j].accession);

puts(b[j].tittle);

puts(b[j].author);
printf("book price is :%d",b[j].cost);
 printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
 }
 else if(strcmp(b[j].author,a2)!=0)
 {
  printf("\nThere is no belongs to  %s books",a2);
 }


}
if(i==0)  printf("\nThere is no belongs to  %s books",a2);
}
//SPECIFIED BOOK

void tbk()
{char book[20];
int j;;
printf("\nEnter a book name");
gets(book);
fflush(stdin);
for(j=0;j<i;j++)
{
if(strcmp(b[j].tittle,book)==0)
{
printf("\naccession number is %d\n",b[j].accession);

puts(b[j].tittle);

puts(b[j].author);
printf("book price is :%d",b[j].cost);
}
else if(strcmp(b[j].tittle,book)!=0)
{
printf("\nThere is no %s  book",book);
}
printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
if(i==0) printf("There is no %s book",book);
}
//NUMBER OF BOOKS IS THERE



void nbk()
{
int j,k=0;
for(j=0;j<i;j++)
{
k++;
}
if(k>1)
printf("\n%d books",k);
else if(k==1)
printf("\n%d book",k);
else
printf("\nThere are no books");
printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}

//ASCENDING ORDER OF ACCESSION NUMBER

void lbk()
{
int j,k,temp;
for(j=0;j<i;j++)
{
for(k=0;k<i-1;k++)
{
if(b[k].accession>b[k+1].accession)
{
temp=b[k].accession;
b[k].accession=b[k+1].accession;
b[k+1].accession=temp;
}
}
   }
for(j=0;j<i;j++)
{
printf("\naccession number is %d\n",b[j].accession);

puts(b[j].tittle);

puts(b[j].author);
printf("book price is :%d",b[j].cost);
   
printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
EXPECTED OUTPUT



A decimal number between 0 and 32 exclusive can be expressed in binary system as x4x3x2x1x0, where xi's are either zero or one. Write a C program that accepts (from the terminal) a decimal number in the above range and prints out the equivalent binary representation with leading bit 1.

A decimal number between 0 and 32 exclusive can be expressed in binary system as x4x3x2x1x0, where xi's are either zero or one. Write a C program that accepts (from the terminal) a decimal number in the above range and prints out the equivalent binary representation with leading bit 1.


PROGRAM

#include <stdio.h>
int binary(int n);
main()
{
   int n, x;
   printf("Enter a decimal number between 0 and 32: ");
   scanf("%d", &n);
   while(n>=0 && n<=32)
   {
      
    x = binary(n);
   printf("BINARY EQUIVALENT OF DECIMAL NUMBER %d IS %d", n, x);
   printf("\nEnter a decimal number between 0 and 32: ");
   scanf("%d", &n);
}
   
   n<0||n>32?printf("Out of range"):printf("");
   
}
int binary(int n)
{
    if (n == 0)
    {
        return 0;
    }
    else
    {
        return (n % 2) + 10 * binary(n/ 2);
    }
}
EXPECTED OUTPUT

  
   

FOR ANY QUERY:nrnvcoding@gmail.com




Write a C program that accepts integers from the keyboard until we enter a zero or a negative number. The program will output the number of positive values entered, the minimum value, the maximum value and the average of all numbers.

Write a C program that accepts integers from the keyboarduntil we enter a zero or a negative number. The program will output the numberof positive values entered, the minimum value, the maximum value and theaverage of all numbers.

PROGRAM

#include<stdio.h>
main()
{
int max,min,i=0,arr[10],n,e=0;
float k,avg=0;
while(i>=0)
{
printf("Enter an integer:");
scanf("%d",&arr[i]);
i++;
if(arr[i-1]<=0)  break;
}



for(i=0;arr[i]>0;i++)
    {
    arr[i]>0?e++:printf("");
   
}
e>=1?printf("\nTotal number of positive numbers entered is %d\n",e):printf("There are no positive number");

   if(e>=1)
   {
 
   min=arr[0];
   max=arr[0];
   for(i=1;arr[i]>0;i++)
   {
   
    if(min>arr[i])
    {
    min=arr[i];
   
}
else if(max<arr[i])
{
max=arr[i];
}
}

   printf("\nSmall one is:%d\nLarge one is:%d",min,max); 

   for(i=0;arr[i]>0;i++)
   {
    avg=avg+arr[i];
   }
 
 
   for(i=0;arr[i]>0;i++)
   {
    k=avg/(i+1);
   }
printf("\nAverage is %f",k);
}
}
https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw

EXPECTED OUTPUT
https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw






   
 
   















WITHOUT USING IF-ELSE CONDITION FOR MULTIPLES AND EVEN NUMBERS IN C PROGRAM

Write a C program without using if-else construct that does the following. It accepts a sequence of positive integers between 1 and 9 both inclusive from the key-board. The program will stop accepting input once an integer outside the range is entered. The program will finish by printing the total number multiples of 3 and total number of even integers entered.


program:



#include<stdio.h>
main()
{
 int n,even_num=0,three_mul=0;
 printf("Enter an integer");
 scanf("%d",&n);
 while(n>0&&n<10)
 {
  n%2==0?even_num++:printf("");
  n%3==0?three_mul++:printf("");
  printf("Enter an integer");
        scanf("%d",&n);
 }
 even_num==1?printf("There is an only one even number\n"):printf("There are %d even numbers\n",even_num);

 three_mul==1?printf("There is an only one Three multiple number"):printf("There are %d Three multiples",three_mul);

}expected output:



https://www.youtube.com/channel/UCfg0HhLUIrgd_45YaytZrVw

Manhattan Distance Heuristic

#include<stdio.h> #include<stdlib.h> struct node{  int arr[10][10];  int i,j;  int md; }; int a[10][10]; struct node*...