C Program for Circular QUEUE Operations

Data structures using C,
C Program to implement circular queue. Queue is a abstract data type, In which entities are inserted into the rear end and deleted from the front end. In circular queue is connected to end to end, i,e rear and front end are connected. Compare to normal queue, Circular queue is more advantages. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#define SIZE 5 /* Size of Circular Queue */
int CQ[SIZE], f = -1, r = -1; /* Global declarations */

CQinsert(int elem) { /* Function for Insert operation */
if (CQfull())
printf("nn Overflow!!!!nn");
else {
if (f == -1)
f = 0;
r = (r + 1) % SIZE;
CQ[r] = elem;
}
}

int CQdelete() { /* Function for Delete operation */
int elem;
if (CQempty()) {
printf("nnUnderflow!!!!nn");
return (-1);
} else {
elem = CQ[f];
if (f == r) {
f = -1;
r = -1;
} /* Q has only one element ? */
else
f = (f + 1) % SIZE;
return (elem);
}
}

int CQfull() { /* Function to Check Circular Queue Full */
if ((f == r + 1) || (f == 0 && r == SIZE - 1))
return 1;
return 0;
}

int CQempty() { /* Function to Check Circular Queue Empty */
if (f == -1)
return 1;
return 0;
}

display() { /* Function to display status of Circular Queue */
int i;
if (CQempty())
printf(" n Empty Queuen");
else {
printf("Front[%d]->", f);
for (i = f; i != r; i = (i + 1) % SIZE)
printf("%d ", CQ[i]);
printf("%d ", CQ[i]);
printf("<-[%d]Rear", r);
}
}

main() { /* Main Program */
int opn, elem;
do {
clrscr();
printf("n ### Circular Queue Operations ### 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);
CQinsert(elem);
break;
case 2:
elem = CQdelete();
if (elem != -1)
printf("nnDeleted Element is %d n", elem);
break;
case 3:
printf("nnStatus of Circular 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 Programs
Data Structures

Learn C Programming

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program for Infix to Postfix Conversion.

C Program for Infix to Postfix Conversion. Here we covert the infix expression to postfix expression by using stack. for example a*b-c/d is the infix expression, and equivalent postfix expression is: ab*cd/-. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#define SIZE 50 /* Size of Stack */
#include <ctype.h>
char s[SIZE];
int top = -1; /* Global declarations */

push(char elem) { /* Function for PUSH operation */
s[++top] = elem;
}

char pop() { /* Function for POP operation */
return (s[top--]);
}

int pr(char elem) { /* Function for precedence */
switch (elem) {
case '#':
return 0;
case '(':
return 1;
case '+':
case '-':
return 2;
case '*':
case '/':
return 3;
}
}

main() { /* Main Program */
char infx[50], pofx[50], ch, elem;
int i = 0, k = 0;
printf("nnRead the Infix Expression ? ");
scanf("%s", infx);
push('#');
while ((ch = infx[i++]) != '') {
if (ch == '(')
push(ch);
else if (isalnum(ch))
pofx[k++] = ch;
else if (ch == ')') {
while (s[top] != '(')
pofx[k++] = pop();
elem = pop(); /* Remove ( */
} else { /* Operator */
while (pr(s[top]) >= pr(ch))
pofx[k++] = pop();
push(ch);
}
}
while (s[top] != '#') /* Pop from stack till empty */
pofx[k++] = pop();
pofx[k] = ''; /* Make pofx as valid string */
printf("nnGiven Infix Expn: %s Postfix Expn: %sn", infx, pofx);
}

Read more Similar C Programs
Data Structures

Learn C Programming

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to compare two strings

C Strings:
C Program to accepts two strings and compare them, Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string. The string comparison starts with the first character in each string and continues with subsequent characters until the corresponding characters differ or until the end of the strings is reached. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/              
#include<stdio.h>
#include<conio.h>

void main()
{
 int count1=0,count2=0,flag=0,i;
 char str1[10],str2[10];

 clrscr();
 puts("Enter a string:");
 gets(str1);

 puts("Enter another string:");
 gets(str2);
 /*Count the number of characters in str1*/
 while (str1[count1]!='')
  count1++;
 /*Count the number of characters in str2*/
 while (str2[count2]!='')
  count2++;
 i=0;

 /*The string comparison starts with the first character in each string and
 continues with subsequent characters until the corresponding characters
 differ or until the end of the strings is reached.*/

 while ( (i < count1) && (i < count2))
 {
  if (str1[i] == str2[i])
  {
   i++;
   continue;
  }
  if (str1[i]<str2[i])
  {
   flag = -1;
   break;
  }
  if (str1[i] > str2[i])
  {
   flag = 1;
   break;
  }
 }

 if (flag==0)
  printf("Both strings are equaln");
 if (flag==1)
  printf("String1 is greater than string2n", str1, str2);
 if (flag == -1)
  printf("String1 is less than string2n", str1, str2);
 getch();
}
Read more Similar C Programs
Searching in C

C Strings

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

To get regular updates on new C programs, you can Follow @c_program

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

Share this program with your Facebook friends now! by liking it
Like to get updates right inside your feed reader? Grab our feed!
(c) www.c-program-example.com

C Program to demonstrate time functions.

C Program to demonstrate time functions. time.h library function is used to get and manipulate date and time functions. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h> /* NULL */
#include <time.h> /* ctime, asctime */

main()
{
time_t now; /* define 'now'. time_t is probably
* a typedef */

/* Calender time is the number of
* seconds since 1/1/1970 */

now = time((time_t *)NULL); /* Get the system time and put it
* into 'now' as 'calender time' */

printf("%s", ctime(&now)); /* Format data in 'now'
* NOTE that 'ctime' inserts a
* 'n' */

/*********************************************************************/

/* Here is another way to extract the time/date information */

time(&now);

printf("%s", ctime(&now)); /* Format data in 'now' */

/*********************************************************************/

{
struct tm *l_time;

l_time = localtime(&now); /* Convert 'calender time' to
* 'local time' - return a pointer
* to the 'tm' structure. localtime
* reserves the storage for us. */
printf("%s", asctime(l_time));
}

/*********************************************************************/

time(&now);
printf("%s", asctime(localtime( &now )));

/*********************************************************************/

{
struct tm *l_time;
char string[20];

time(&now);
l_time = localtime(&now);
strftime(string, sizeof string, "%d-%b-%yn", l_time);
printf("%s", string);
}


}
Read more Similar C Programs
Learn C Programming

Simple C Programs

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate macros.

C Program to demonstrate macros. Macro is a piece of text that is expanded by the preprocessor part of the compiler. This is used in to expand text before compiling. Macro definitions (#define), and conditional inclusion (#if). In many C implementations, it is a separate program invoked by the compiler as the first part of translation.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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#define SQUARE(x) x*x

main()
{
int value=3;

printf("%d n", SQUARE(value));
}
Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate goto statement

C Program to demonstrate goto statement . goto statement jumps the control from one point to another locally(within a function). In this program we perform a division checking for divide by zero by using the goto statement.

The Program

#include <stdio.h>
#include <stdlib.h>
main()
{
char data[100];
double num1, num2;
printf("\nPlease enter a number ==> " );
gets(data);
num1 = atof(data);
printf("\nPlease enter a number ==> " );
gets(data);
num2 = atof(data);
/* Stop a divide by zero with
* the goto statement.
*/
if ( num2 == 0.0 ) goto end_prog;
printf("\n%4.2f divided by %4.2f is %4.2f\n", num1, num2, num1/num2);
end_prog:
printf("\nProgram ended");
}
view raw goto.c hosted with ❤ by GitHub

Sample Output

Similar C Programs

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

To get regular updates on new C programs, you can Follow @c_program

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate Enumeration.

C Program to demonstrate Enumeration. An enum(Enumeration) is a user-defined type consisting of a set of named constants called enumerators. This Program will return the month in a year. I.E. It returns 9 for September. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include<stdio.h>
main()
{
/*
* Define a list of aliases
*/
enum months {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
/* A A
| |
| |
| ------- list of aliases.
-------------- Enumeration tag. */


enum months month; /* define 'month' variable of type 'months' */

printf("%dn", month=Sep); /* Assign integer value via an alias
* This will return a 9 */
}
Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate the ‘do’ statement.

C Program to demonstrate the ‘do’ statement. The C do while statement creates a structured loop that executes as long as a specified condition is true at the end of each pass through the loop. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>

main()
{
int i=1; /* Define an integer variable. */

/*
* The block is executed. Then the i <= 10
* expression is evaluated. If TRUE the block
* is executed again.
*/
do
{
printf ("i is %in", i);
i++;
} while (i <= 10);

}
Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C program to Demonstrate the #define pre-processor.

C Program to demonstrate #define pre-processor. Macro is a piece of text that is expanded by the pre-processor part of the compiler. This is used in to expand text before compiling. Macro definitions (#define), and conditional inclusion (#if). In many C implementations, it is a separate program invoked by the compiler as the first part of translation.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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#define EQ ==

main ()
{
/* the EQ is translated to == by
* the C pre-processor. COOL!
*/
if ( 5 EQ 5 ) printf("define works...n");
}
Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to illustrate Arithmetic operators

C Program to illustrate Airthmatic operators. This program takes an integer variable i and performs the basic arithmetic functions like Addition, Subtraction, Multiplication, Division, Unary Addition and Unary Subtraction. 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 [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                                  Happy Coding
***********************************************************/

# include <stdio.h>

int main()
{

 int i;

 i = 5;
 printf("The Value of i is : %d", i);
 i = i  + 5;
 printf("nThe Value of i is : %d", i);
 i = i - 2;
 printf("nThe Value of i is : %d", i);
 i = i  * 2;
 printf("nThe Value of i is : %d", i);
 i = i / 4;
 printf("nThe Value of i is : %d", i);
 i++;
 printf("nThe Value of i is : %d", i);
 i++;
 printf("nThe Value of i is : %d", i);
 i --;
 printf("nThe Value of i is : %d", i);

 getchar();

 return(0) ;

}
Read more Similar C Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com