Oct 4, 2011

C Program to illustrate Airthmatic 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 info@c-program-example.com
* 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

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 Program to Illustrate all data types.

C Program to Illustrate all data types.  The four different data types are assigned the corresponding values are printed. We can see that, to print a Integer value we give a %d sign, similarly for Character %c, Float %f and for Double %e.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>

int main()
{
 int   sum;
 float money;
 char  letter;
 double pi;

 sum = 10;   /* assign integer value*/
 money = 2.21; /* assign float value*/
 letter = 'A'; /* assign character value */
 pi = 2.01E6;  /* assign a double value */

 printf("value of sum = %d\n", sum );
 printf("value of money = %f\n", money );
 printf("value of letter = %c\n", letter );
 printf("value of pi = %e\n", pi );
 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

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 Program to print the values stored in identifiers.

C Program to print the values stored in identifiers. An identifier can be in lowercase or uppercase. The upper and lower case are NOT interchangeable. The above program should give you an idea that C is case sensitive. "Sum" and "sum" are different variables and so have different values. The _ (underscore) character can also be included and is considered a letter. So try a program by using some other identifiers using underscore. 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>

int main()
{
 int sum, Sum ;

 sum = 10 ;
 Sum = 20;

 printf(" The value stored in two different identifiers  
   are : ");

 printf(" \n sum is : %d \n Sum is %d \n", sum, Sum);

 getchar();

 return(0);
}
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

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 program to implement stack.

Data structures using C,
Write a C program to implement stack. Stack is a data structure in which the objects are arranged in a non linear order. In stack, elements are added or deleted from only one end, i.e. top of the stack. Stack is a LIFO data structure. LIFO - Last in First Out Perform PUSH(insert operation), POP(Delete operation) and Display stack . 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>
#define MAXSIZE 5

struct stack            /* Structure definition for stack */
{
 int stk[MAXSIZE];
 int top;
};

typedef struct stack STACK;
STACK s;

/* Function declaration/Prototype*/

void push (void);
int  pop(void);
void display (void);

void main ()
{
 int choice;
 int option = 1;

 clrscr ();

 s.top = -1;

 printf ("STACK OPERATION\n");
 while (option)
 {
  printf ("------------------------------------------\n");
  printf ("   1 --> PUSH            \n");
  printf ("   2 --> POP            \n");
  printf ("   3 --> DISPLAY            \n");
  printf ("   4 --> EXIT     \n");
  printf ("------------------------------------------\n");

  printf ("Enter your choice\n");
  scanf ("%d", &choice);

  switch (choice)
  {
  case 1: push();
  break;
  case 2: pop();
  break;
  case 3: display();
  break;
  case 4: return;
  }

  fflush (stdin);
  printf ("Do you want to continue(Type 0 or 1)?\n");
  scanf ("%d", &option);
 }
}

/*Function to add an element to the stack*/
void push ()
{
 int num;
 if (s.top == (MAXSIZE - 1))
 {
  printf ("Stack is Full\n");
  return;
 }
 else
 {
  printf ("Enter the element to be pushed\n");
  scanf ("%d", &num);
  s.top = s.top + 1;
  s.stk[s.top] = num;
 }
 return;
}


/*Function to delete an element from the stack*/
int pop ()
{
 int num;
 if (s.top == - 1)
 {
  printf ("Stack is Empty\n");
  return (s.top);
 }
 else
 {
  num = s.stk[s.top];
  printf ("poped element is = %d\n", s.stk[s.top]);
  s.top = s.top - 1;
 }
 return(num);
}

/*Function to display the status of the stack*/
void display ()
{
 int i;
 if (s.top == -1)
 {
  printf ("Stack is empty\n");
  return;
 }
 else
 {
  printf ("\nThe status of the stack is\n");
  for (i = s.top; i >= 0; i--)
  {
   printf ("%d\n", s.stk[i]);
  }
 }
 printf ("\n");
}
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

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 program to illustrate the operations of singly linked list.

Data structures using C,
C program to illustrate the operations of singly linked list. Linked list is a data structure in which the objects are arranged in a linear order. Linked List contains group of nodes, in which each node contains two fields, one is data field and another one is the reference field which contains the address of next node. In this program we insert, delete, search, and display the linked list. 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>
#include <string.h>
#define MAX 30

struct EMP
{
 int  empno;
 char empName[MAX];
 char designation[MAX];
 struct EMP *next;
};

/*********************************************************************/
/* Function to insert a node at the front of the linked list.        */
/* front: front pointer, id: employee ID, name: employee name        */
/* desg: Employee designation           */
/* Returns the new front pointer.                                    */
/*********************************************************************/

struct EMP* insert(struct EMP *front, int id, char name[], char desg[])
{
 struct EMP *newnode;

 newnode = (struct EMP*) malloc(sizeof(struct EMP));

 if (newnode == NULL)
 {
  printf("\nAllocation failed\n");
  exit(2);
 }
 newnode->empno = id;
 strcpy(newnode->empName, name);
 strcpy(newnode->designation, desg);
 newnode->next = front;
 front = newnode;
 return(front);
}                             /*End of insert() */

/* Function to display a node in a linked list */
void printNode(struct EMP *p)
{
 printf("\nEmployee Details...\n");
 printf("\nEmp No    : %d", p->empno);
 printf("\nName           : %s", p->empName);
 printf("\nDesignation    : %s\n", p->designation);
 printf("-------------------------------------\n");
}                               /*End of printNode() */

/* ********************************************************/
/* Function to deleteNode a node based on employee number     */
/* front: front pointer, id: Key value                    */
/* Returns: the modified list.                            */
/* ********************************************************/

struct EMP* deleteNode(struct EMP *front, int id)
{
 struct EMP *ptr;
 struct EMP *bptr;    /* bptr is pointing to the node behind ptr */


 if (front->empno == id) 
 {
  ptr = front;
  printf("\nNode deleted:");
  printNode(front);
  front = front->next;
  free(ptr);
  return(front);
 }

 for(ptr=front->next, bptr=front; ptr!=NULL; ptr=ptr->next, bptr=bptr->next)
 {
  if (ptr->empno == id)
  {
   printf("\nNode deleted:");
   printNode(ptr);
   bptr->next = ptr->next;
   free(ptr);
   return(front);
  }
 }
 printf("\nEmployee Number %d not found ", id);
 return(front);
}                              /*End of deleteNode() */

/*****************************************************************/
/* Function to search the nodes in a linear fashion based emp ID */
/* front: front pointer, key: key ID.                             */
/*****************************************************************/
void search(struct EMP *front, int key)
{
 struct EMP *ptr;

 for (ptr = front; ptr != NULL; ptr = ptr -> next)
 {
  if (ptr->empno == key)
  {
   printf("\nKey found:");
   printNode(ptr);
   return;
  } 
 }
 printf("\nEmployee Number %d not found ", key);
}                           /*End of search() */

/* Function to display the linked list */
void display(struct EMP *front)
{
 struct EMP *ptr;

 for (ptr = front; ptr != NULL; ptr = ptr->next)
 {
  printNode(ptr);
 }
}                         /*End of display() */

/* Function to display the menu of operations on a linked list */
void menu()
{
 printf("---------------------------------------------\n");
 printf("Press 1 to INSERT a node into the list       \n");
 printf("Press 2 to DELETE a node from the list       \n");
 printf("Press 3 to DISPLAY the list                  \n");
 printf("Press 4 to SEARCH the list                   \n");
 printf("Press 5 to EXIT                              \n");
 printf("---------------------------------------------\n");
}                      /*End of menu() */

/* Function to select the option */
char option()
{
 char choice;

 printf("\n\n>> Enter your choice: ");
 switch(choice=getche())
 {
 case '1':
 case '2':
 case '3':
 case '4':
 case '5':   return(choice);
 default :    printf("\nInvalid choice.");
 }
 return choice;
}            /*End of option() */

/* The main() program begins */
void main()
{
 struct EMP *linkList;
 char name[21], desig[51];
 char choice;
 int eno;

 linkList = NULL;

 printf("\nWelcome to demonstration of singly linked list\n");

 menu();       /*Function call */

 do {
  choice = option();          /*to choose oeration to be performed */

  switch(choice)
  {
  case '1': printf("\nEnter the Employee Number      : ");
  scanf("%d", &eno);

  printf("Enter the Employee name        : ");
  fflush(stdin);
  gets(name);

  printf("Enter the Employee Designation : ");
  gets(desig);

  linkList = insert(linkList, eno, name, desig);
  break;

  case '2': printf("\n\nEnter the employee number to be deleted: ");
  scanf("%d", &eno);

  linkList = deleteNode(linkList, eno);
  break;

  case '3': if (linkList == NULL)
  {
   printf("\nList empty.");
   break;
  }
  display(linkList);
  break;

  case '4': printf("\n\nEnter the employee number to be searched: ");
  scanf("%d", &eno);

  search(linkList, eno);
  break;

  case '5': break;
  }
 } while (choice != '5');
}             /*End fo main()*/
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

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 program to create a linked list and display the elements in the list.

Data structures using C,
C program to create a linked list and display the elements in the list. Linked list is a data structure in which the objects are arranged in a linear order. Linked List contains group of nodes, in which each node contains two fields, one is data field and another one is the reference field which contains the address of next node. 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 <alloc.h>
#include <stdlib.h>

void main()
{
 struct node
 {
  int num;
  struct node *ptr;
 };

 typedef struct node NODE;

 NODE *head, *first, *temp=0;
 int count = 0;
 int choice = 1;
 first = 0;

 while(choice)
 {
  head =(NODE*) malloc(sizeof(NODE));
  printf("Enter the data item\n");
  scanf("%d", &head-> num);

  if(first != 0)
  {
   temp->ptr = head;
   temp = head;
  }
  else
  {
   first = temp = head;
  }
  fflush(stdin);
  printf("Do you want to continue(Type 0 or 1)?\n");
  scanf("%d", &choice);

 }         /* End of while */

 temp->ptr = 0;
 temp = first;  /* reset temp to the beginning*/
 printf("\nstatus of the linked list is\n");

 while(temp!=0)
 {
  printf("%d=>", temp->num);
  count++;
  temp = temp -> ptr;
 }
 printf("NULL\n");
 printf("No. of nodes in the list = %d\n", count);
}  /* End of main*/
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

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 program to illustrate as to how the data stored on the disk is read.

C Program to illustrate as to how the data stored on the disk is read. In this program we use the C File i/o operations to read the file from disk. fopen function open the files for reading, and fclose() closes the file. 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>

void main()
{
 FILE *fptr;
 char filename[15];
 char ch;

 printf("Enter the filename to be opened\n");
 gets(filename);

 fptr = fopen (filename, "r");  /*open for reading*/

 if (fptr == NULL)
 {
  printf("Cannot open file\n");
  exit(0);
 }

 ch = fgetc(fptr);

 while (ch != EOF)
 {
  printf ("%c", ch);
  ch = fgetc(fptr);
 }

 fclose(fptr);
}        /* End of main () */
Read more Similar C Programs
C Basic

C File i/o
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!

C Program for file operations.

C program to create a file called emp.txt and store information about a person, in terms of his name, age and salary.
/***********************************************************
* 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>

void main()
{
	FILE *fptr;
	char name[20];
	int age;
	float salary;

	fptr = fopen ("emp.txt", "w"); /*open for writing*/

	if (fptr == NULL)
	{
		printf("File does not exists\n");
		return;
	}

	printf("Enter the name\n");
	scanf("%s", name);
	fprintf(fptr, "Name    = %s\n", name);

	printf("Enter the age\n");
	scanf("%d", &age);
	fprintf(fptr, "Age     = %d\n", age);

	printf("Enter the salary\n");
	scanf("%f", &salary);
	fprintf(fptr, "Salary  = %.2f\n", salary);

	fclose(fptr);
}
/*Please note that you have to open the file called emp.txt in the directory*/
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!

C program to find the size of a union.

C program to find the size of a union. Union is a collection of different data types like a structure but it gives the single piece of memory for all data types. In this program we use the sizeof() operator to find the size of union. sizeof() return the size of data types in bytes. 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>

void main()
{
 union sample
 {
  int   m;
  float n;
  char  ch;
 };

 union sample u;

 printf("The size of union =%d\n", sizeof(u));

 /*initialization */

 u.m = 25;
 printf("%d %f %c\n", u.m, u.n,u.ch);

 u.n = 0.2;
 printf("%d %f %c\n", u.m, u.n,u.ch);

 u.ch = 'p';
 printf("%d %f %c\n", u.m, u.n,u.ch);
}     /*End of main() */
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

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!

Oct 3, 2011

C program to find the sum of two-dimensional arrays using Dynamic Memory Allocation.

Arrays in C
C Program to find the sum of two-dimensional arrays using Dynamic Memory Allocation. The malloc() function allocates the dynamic memory to variables of specified bytes.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 <alloc.h>
#include <stdlib.h>

void main()
{
 int i,n;
 int *a,*b,*c;

 printf("How many Elements in each array...\n");
 scanf("%d", &n);

 a = (int *) malloc(n*sizeof(int));
 b = (int *) malloc(n*sizeof(int));
 c =( int *) malloc(n*sizeof(int));

 printf("Enter Elements of First List\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",a+i);
 }

 printf("Enter Elements of Second List\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",b+i);
 }

 for(i=0;i<n;i++)
 {
  *(c+i) = *(a+i) + *(b+i);
 }

 printf("Resultant List is\n");
 for(i=0;i<n;i++)
 {
  printf("%d\n",*(c+i));
 }

}     /* End of main() */
Read more Similar C Programs
Array In C

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

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 Program to sort the matrix rows and columns.

C Program to sort the matrix rows and columns. This C program accept a order MxN Matrix, and sort all rows of the matrix in ascending order and all columns in descending order . In this program, we use the for statement to read two dimension arrays. 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>

void main ()
{
 static int ma[10][10],mb[10][10];
 int i,j,k,a,m,n;

 printf ("Enter the order of the matrix \n");
 scanf ("%d %d", &m,&n);

 printf ("Enter co-efficients of the matrix \n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   scanf ("%d",&ma[i][j]);
   mb[i][j] = ma[i][j];
  }
 }
 printf ("The given matrix is \n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   printf (" %d",ma[i][j]);
  }
  printf ("\n");
 }

 printf ("After arranging rows in ascending order\n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   for (k=(j+1);k<n;++k)
   {
    if (ma[i][j] > ma[i][k])
    {
     a = ma[i][j];
     ma[i][j] = ma[i][k];
     ma[i][k] = a;
    }
   }
  }
 }      /* End of outer for loop*/

 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   printf (" %d",ma[i][j]);
  }
  printf ("\n");
 }

 printf ("After arranging the columns in descending order \n");
 for (j=0;j<n;++j)
 {
  for (i=0;i<m;++i)
  {
   for (k=i+1;k<m;++k)
   {
    if (mb[i][j] < mb[k][j])
    {
     a = mb[i][j];
     mb[i][j] = mb[k][j];
     mb[k][j] = a;
    }
   }
  }
 }       /* End of outer for loop*/

 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   printf (" %d",mb[i][j]);
  }
  printf ("\n");
 }

}  /*End of main() */
Read more Similar C Programs
C Basic.

C Matrix.

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!

C program to find the sparse matrix

C program to accept a matrix and determine whether it is a sparse matrix or not?. A sparse matrix is a matrix, which has more zero elements than nonzero elements. 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>

void main ()
{
 static int m1[10][10];
 int i,j,m,n;
 int counter=0;

 printf ("Enter the order of the matix\n");
 scanf ("%d %d",&m,&n);

 printf ("Enter the co-efficients of the matix\n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   scanf ("%d",&m1[i][j]);
   if (m1[i][j]==0)
   {
    ++counter;
   }
  }
 }
 if (counter>((m*n)/2))
 {
  printf ("The given matrix is sparse matrix \n");
 }
 else
  printf ("The given matrix is not a sparse matrix \n");

 printf ("There are %d number of zeros",counter);

}       /* EN dof main() */
Read more Similar C Programs
Matrix Programs
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!

C program to accept an integer find the sum of the digits in it

C program to accept an integer find the sum of the digits in it. In this program, we accept an integer and get the digits by using while() and % operator, after that we add that digits to the sum variable. 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>

void main()
{
 long num, temp, digit, sum = 0;

 printf("Enter the number\n");
 scanf("%ld", &num);

 temp = num;

 while(num > 0)
 {
  digit = num % 10;
  sum  = sum + digit;
  num /= 10;
 }

 printf("Given number =%ld\n", temp);
 printf("Sum of the digits %ld =%ld\n", temp, sum);
}              /* End of main()*/
Read more Similar C Programs
C Basic

Airthmatic Operators

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!

C Program to interchange the main diagonal elements of the matrix

C Program to interchange the main diagonal elements of the matrix. This Program will accept a matrix of order M x N and store its elements and interchange the main diagonal elements of the matrix with that of the secondary diagonal elements .   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
***********************************************************/
void main ()
{

 static int ma[10][10];
 int i,j,m,n,a;

 printf ("Enetr the order of the matix \n");
 scanf ("%d %d",&m,&n);

 if (m ==n )
 {
  printf ("Enter the co-efficients of the matrix\n");
  for (i=0;i<m;++i)
  {
   for (j=0;j<n;++j)
   {
    scanf ("%dx%d",&ma[i][j]);
   }
  }

  printf ("The given matrix is \n");
  for (i=0;i<m;++i)
  {
   for (j=0;j<n;++j)
   {
    printf (" %d",ma[i][j]);
   }
   printf ("\n");
  }

  for (i=0;i<m;++i)
  {
   a = ma[i][i];
   ma[i][i]   = ma[i][m-i-1];
   ma[i][m-i-1] = a;
  }

  printf ("THe matrix after changing the \n");
  printf ("main diagonal & secondary diagonal\n");
  for (i=0;i<m;++i)
  {
   for (j=0;j<n;++j)
   {
    printf (" %d",ma[i][j]);
   }
   printf ("\n");
  }
 }
 else
  printf ("The givan order is not square matrix\n");

}    /* end of main() */
Read more Similar C Programs
Matrix Programs
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!

C program to find the frequency of odd numbers and even numbers in the input of a matrix

C program to find the frequency of odd numbers and even numbers in the input of a matrix. Program will check the element type, if Matrix element is even, it ads 1 to even counter otherwise ad 1 to odd counter. 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
***********************************************************/

void main ()
{
 static int ma[10][10];
 int i,j,m,n,even=0,odd=0;

 printf ("Enter the order ofthe matrix \n");
 scanf ("%d %d",&m,&n);

 printf ("Enter the coefficients if matrix \n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   scanf ("%d", &ma[i][j]);
   if ((ma[i][j]%2) == 0)
   {
    ++even;
   }
   else
    ++odd;
  }
 }
 printf ("The given matrix is\n");
 for (i=0;i<m;++i)
 {
  for (j=0;j<n;++j)
  {
   printf (" %d",ma[i][j]);
  }
  printf ("\n");
 }

 printf ("\nThe frequency of occurance of odd number  = %d\n",odd);
 printf ("The frequency of occurance of even number = %d\n",even);

}   /* End of main() */
Read more Similar C Programs
Matrix Programs
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!

C Program to find second largesC Program to find second largest and second smallest element in the array.t and second smallest element in the array.

Arrays in C,
C Program to find second largest and second smallest element in the array.  Program will accept a list of data items and find the second largest and second smallest elements in it. And also compute the average of both. And search for the average value whether it is present in the array or not. Display appropriate message on successful search.  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>

void main ()
{
 int number[30];
 int i,j,a,n,counter,ave;

 printf ("Enter the value of N\n");
 scanf ("%d", &n);

 printf ("Enter the numbers \n");
 for (i=0; i<n; ++i)
  scanf ("%d",&number[i]);

 for (i=0; i<n; ++i)
 {
  for (j=i+1; j<n; ++j)
  {
   if (number[i] < number[j])
   {
    a        = number[i];
    number[i] = number[j];
    number[j] = a;
   }
  }
 }

 printf ("The numbers arranged in descending order are given below\n");
 for (i=0; i<n; ++i)
 {
  printf ("%d\n",number[i]);
 }

 printf ("The 2nd largest number is  = %d\n", number[1]);
 printf ("The 2nd smallest number is = %d\n", number[n-2]);

 ave = (number[1] +number[n-2])/2;
 counter = 0;

 for (i=0; i<n; ++i)
 {
  if (ave == number[i])
  {
   ++counter;
  }
 }
 if (counter == 0 )
  printf ("The average of %d  and %d is = %d is not in the array\n", number[1], number[n-2], ave);
 else
  printf ("The average of %d  and %d in the array is %d in numbers\n",number[1], number[n-2], counter);
}           /* End of main() */
Read more Similar C Programs
Array In C

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

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 program to accept N numbers and arrange them in an descending order

C Sorting,
C program to accept N numbers and arrange them in an descending order. Program will accept the array of elements, and returns the elements in descending order. Program use the Bubble sort Technique to sort the Array. 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>

void main ()
{
 int i,j,a,n,number[30];

 printf ("Enter the value of N\n");
 scanf ("%d", &n);

 printf ("Enter the numbers \n");
 for (i=0; i<n; ++i)
  scanf ("%d",&number[i]);

 for (i=0; i<n; ++i)
 {
  for (j=i+1; j<n; ++j)
  {
   if (number[i] < number[j])
   {
    a= number[i];
    number[i] = number[j];
    number[j] = a;
   }
  }
 }

 printf ("The numbers arrenged in descending order are given below\n");
 for (i=0; i<n; ++i)
  printf ("%d\n",number[i]);
}                              /* End of main() */
Read more Similar C Programs
Array In C

Sorting Techniques
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!

C Program to multiply given number by 4 using bitwise operators

C Program to multiply given number by 4 using bitwise operators. Bitwise operators allows to cahnge or edit the specific bits within an integer. Program will multiply a given number by 4 using left shift(<<) bitwise operator. 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
***********************************************************/

/*    c program to multiply given number by 4     *
 *    using bitwise operators                             */

#include <stdio.h>

void main()
{
 long number, tempnum;

 printf("Enter an integer\n");
 scanf("%ld",&number);
 tempnum = number;
 number = number << 2;   /*left shift by two bits*/

 printf("%ld x 4 = %ld\n", tempnum,number);
}
Read more Similar C Programs
Array In C

Sorting Techniques

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!


C Program to check if a given matrix is an identity matrix

C Program to check if a given matrix is an identity matrix or not. If I is theIdentity Matrix,then for any matrix A, IA=AI=A. Program will check the givan matrix is identity or not, and prints the appropriate message. 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
***********************************************************/
/* C Program  Write a C Program to check if a given matrix is an identity matrix */
#include <stdio.h>

void main()
{
 int A[10][10];
 int i, j, R, C, flag =1;

 printf("Enter the order of the matrix A\n");
 scanf("%d %d", &R, &C);

 printf("Enter the elements of matrix A\n");
 for(i=0; i<R; i++)
 {
  for(j=0; j<C; j++)
  {
   scanf("%d",&A[i][j]);
  }
 }
 printf("MATRIX A is\n");
 for(i=0; i<R; i++)
 {
  for(j=0; j<C; j++)
  {
   printf("%3d",A[i][j]);
  }
  printf("\n");
 }

 /* Check for unit (or identity) matrix */

 for(i=0; i<R; i++)
 {
  for(j=0; j<C; j++)
  {
    if((A[i][i] != 1) || (( i != j) && (A[i][j] != 0)))
   {
    flag = 0;
    break;
   }
  }
 }

 if(flag == 1 )
  printf("It is identity matrix\n");
 else
  printf("It is not a identity matrix\n");
}
Read more Similar C Programs
Matrix Programs
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!
-->

C Program to accept two matrices and check if they are equal

C Program to accept two matrices and check if they are equal or not?. Program will accept the two matrices, and return true if their order and their elements are equal, i.e. for all , if a[i][j]==b[i][j]. 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
***********************************************************/

/* Write a C Program to accept two matrices and check if they are equal */

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

void main()
{
 int A[10][10], B[10][10];
 int i, j, R1, C1, R2, C2, flag =1;

 printf("Enter the order of the matrix A\n");
 scanf("%d %d", &R1, &C1);

 printf("Enter the order of the matrix B\n");
 scanf("%d %d", &R2,&C2);

 printf("Enter the elements of matrix A\n");
 for(i=0; i<R1; i++)
 {
  for(j=0; j<C1; j++)
  {
   scanf("%d",&A[i][j]);
  }
 }

 printf("Enter the elements of matrix B\n");
 for(i=0; i<R2; i++)
 {
  for(j=0; j<C2; j++)
  {
   scanf("%d",&B[i][j]);
  }
 }

 printf("MATRIX A is\n");
 for(i=0; i<R1; i++)
 {
  for(j=0; j<C1; j++)
  {
   printf("%3d",A[i][j]);
  }
  printf("\n");
 }

 printf("MATRIX B is\n");
 for(i=0; i<R2; i++)
 {
  for(j=0; j<C2; j++)
  {
   printf("%3d",B[i][j]);
  }
  printf("\n");
 }

 /* Comparing two matrices for equality */

 if(R1 == R2 && C1 == C2)
 {
  printf("Matrices can be compared\n");
  for(i=0; i<R1; i++)
  {
   for(j=0; j<C2; j++)
   {
    if(A[i][j] != B[i][j])
    {
     flag = 0;
     break;
    }
   }
  }
 }
 else
 {  printf(" Cannot be compared\n");
 exit(1);
 }

 if(flag == 1 )
  printf("Two matrices are equal\n");
 else
  printf("But,two matrices are not equal\n");

}
Read more Similar C Programs
Matrix Programs
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!

C Program To Compute X ^ N

C program to compute the value of X ^ N, given X and N as inputs. Program accepts two integers x, n and computes the power of x to the n by using recursion function power().  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 <math.h>

void main()
{
 long int x,n,xpown;
 long int power(int x, int n);

 printf("Enter the values of X and N\n");
 scanf("%ld %ld",&x,&n);

 xpown = power (x,n);

 printf(" %d to the power %d = %ld\n",x,n,xpown);
}

/*Recursive function to computer the X to power N*/

long int power(int x, int n)
{
 if (n==1)
  return(x);
 else if ( n%2 == 0)
  return (pow(power(x,n/2),2));  /*if n is even*/
 else
  return (x*power(x, n-1));     /* if n is odd*/
}
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!

C Program to implement strlen function

Write a c program to find the length of a string without using the built-in function strlen(). Program will calculate the length of the string using for loop by going through each character of the string, till its end. 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>

void main()
{
 char string[50];
 int  i, length = 0;

 printf("Enter a string\n");
 gets(string);

 for (i=0; string[i] != '\0'; i++) /*keep going through each */
 {                                 /*character of the string */
  length++;                     /*till its end */
 }
 printf("The length of a string is the number of characters in it\n");
 printf("So, the length of %s =%d\n", string, length);
}
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

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!