# K & R C Programs Exercise 5-1.

K and R C, Solution to Exercise 5-1:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
C Program to get next integer from input into space, so that getint treats a + or – not followed by a digit as a valid representation of zero and fix it to push such a character back on the input. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact info@c-program-example.com* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/include<ctype.h>int getch(void);void ungetch(int);/* getint:  get next integer from input into *pn */int getint(int *pn){ int c, sign, sawsign; while (isspace(c = getch()))   /* skip white space */  ; if (!isdigit(c) && c != EOF && c != '+' && c != '-') {  ungetch(c);    /* it's not a number */  return 0; } sign = (c == '-') ? -1 : 1; if (sawsign = (c == '+' || c == '-'))  c = getch(); if (!isdigit(c)) {  ungetch(c);  if (sawsign)   ungetch((sign == -1) ? '-' : '+');  return 0; } for (*pn = 0; isdigit(c); c = getch())  *pn = 10 * *pn + (c - '0'); *pn *= sign; if (c != EOF)  ungetch(c); return c;}`
`Read more Similar C ProgramsC BasicC StringsK and R C Programs Exercise`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# C Program for Simple DSC order Priority QUEUE Implementation

Data structures using C,Priority QUEUE is a abstract data type in which the objects are inserted with respect to certain priority. In this program, we created the simple descending order priority queue, here items are inserted in descending order. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact info@c-program-example.com* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#define SIZE 5            /* Size of Queue */int PQ[SIZE],f=0,r=-1;       /* Global declarations */PQinsert(int elem){ int i;       /* Function for Insert operation */ if( Qfull()) printf("nn Overflow!!!!nn"); else {  i=r;  ++r;  while(PQ[i] <= elem && i >= 0) /* Find location for new elem */  {   PQ[i+1]=PQ[i];   i--;  }  PQ[i+1]=elem; }}int PQdelete(){                      /* Function for Delete operation */ int elem; if(Qempty()){ printf("nnUnderflow!!!!nn"); return(-1); } else {  elem=PQ[f];  f=f+1;  return(elem); }}int Qfull(){                     /* Function to Check Queue Full */ if(r==SIZE-1) return 1; return 0;}int Qempty(){                    /* Function to Check Queue Empty */ if(f > r) return 1; return 0;}display(){                  /* Function to display status of Queue */ int i; if(Qempty()) printf(" n Empty Queuen"); else {  printf("Front->");  for(i=f;i<=r;i++)   printf("%d ",PQ[i]);  printf("<-Rear"); }}main(){                         /* Main Program */ int opn,elem; do {  clrscr();  printf("n ### Priority Queue Operations(DSC order) ### nn");  printf("n Press 1-Insert, 2-Delete,3-Display,4-Exitn");  printf("n Your option ? ");  scanf("%d",&opn);  switch(opn)  {  case 1: printf("nnRead the element to be Inserted ?");  scanf("%d",&elem);  PQinsert(elem); break;  case 2: elem=PQdelete();  if( elem != -1)   printf("nnDeleted Element is %d n",elem);  break;  case 3: printf("nnStatus of Queuenn");  display(); break;  case 4: printf("nn Terminating nn"); break;  default: printf("nnInvalid Option !!! Try Again !! nn");  break;  }  printf("nnnn  Press a Key to Continue . . . ");  getch(); }while(opn != 4);}`
`Read more Similar C ProgramsData StructuresLearn C Programming`

You can easily select the code by double clicking on the code area above.