Mar 16, 2012

C program to Demonstrate the Recursive function.

Write a C program to demonstrate the recursive function.
Recursion  is the programming technique that a process invoking itself again and again. In this program, We reverse the given number and checks it is a palindrome or not. 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<stdio.h>
#include<conio.h>

int main(){
 clrscr();
 int num,num1,rev;
 printf("\nEnter a number :\n");
 scanf("%d",&num);
 num1=num;
 //call recursive function
 rev=reverse(num);

 printf("\nAfter reverse the number is :\n%d",rev);
 if(num1==rev){
  printf("\n\nNumber  %d is Palindrome\n",num1);
 }else
 {
  printf("\n\nNumber  %d is NOT a Palindrome\n",num1);
 }

 return 0;
}
int sum=0,r;
reverse(int num){
 if(num){
  r=num%10;
  sum=sum*10+r;
  reverse(num/10);
 }
 else
  return sum;
 return sum;
}

Read more Similar C Programs
Learn C Programming
Recursion
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

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!
To browse more C Programs visit this link

Mar 14, 2012

C program to count the leaves of the binary tree.

Write a C program to count the leaves of the binary tree.
Binary tree is the ordered directed tree data structure, in which each node has at most two nodes.
A node is called as a leaf node,  if it does not contains any child elements. In this program, We used the structures to create the binary tree.
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 <stdio.h>
#include <stdlib.h>
#include <conio.h>

struct node
{
 int data;
 struct node* leftnode;
 struct node* rightnode;
};

//get the leaves count
unsigned int getLeafCount(struct node* node)
{
 if(node == NULL)
  return 0;
 if(node->leftnode == NULL && node->rightnode==NULL)
  return 1;
 else
  return getLeafCount(node->leftnode)+
    getLeafCount(node->rightnode);
}


struct node* newNode(int data)
{
 struct node* node = (struct node*)
  malloc(sizeof(struct node));
 node->data = data;
 node->leftnode = NULL;
 node->rightnode = NULL;

 return(node);
}


int main()
{

 clrcsr();
 struct node *root = newNode(1);
 root->leftnode = newNode(2);
 root->rightnode = newNode(3);
 root->leftnode->leftnode = newNode(4);
 root->leftnode->rightnode = newNode(5); 


 printf("\n\nLeaf count of the binary tree is %d", getLeafCount(root));

 getch();
 return 0;
}


Read more Similar C Programs
Data Structures
Breadth First Search(BFS)
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

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!

To browse more C Programs visit this link

Mar 13, 2012

C Program to implement hashing.

Write a C Program to implement hashing.
Hashing is the function or routine used to assign the key values to the each entity in the database. Using hashing, We can easily access or search the values from database.
In this program we used the open addressing hashing, also called as closed hashing.
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<stdio.h>
#include<conio.h>
void main() {
 int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 int n, value;
 int temp, hash;
 clrscr();
 printf("\nEnter the value of n(table size):");
 scanf("%d", &n);
 do {
  printf("\nEnter the hash value");
  scanf("%d", &value);
  hash = value % n;
  if (a[hash] == 0) {
   a[hash] = value;
   printf("\na[%d]the value %d is stored", hash, value);
  } else {
   for (hash++; hash < n; hash++) {
    if (a[hash] == 0) {
     printf("Space is allocated give other value");
     a[hash] = value;
     printf("\n a[%d]the value %d is stored", hash, value);
     goto menu;
    }
   }

   for (hash = 0; hash < n; hash++) {
    if (a[hash] == 0) {
     printf("Space is allocated give other value");
     a[hash] = value;
     printf("\n a[%d]the value %d is stored", hash, value);
     goto menu;
    }
   }
   printf("\n\nERROR\n");
   printf("\nEnter '0' and press 'Enter key' twice to exit");

  }

  menu:

  printf("\n Do u want enter more");

  scanf("%d", &temp);

 }

 while (temp == 1);

 getch();

}

Read more Similar C Programs
C Basic
C Data Structure
Search Algorithms.
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

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!

To browse more C Programs visit this link