C Program to implement FCFS algorithm.

Write a C Program to implement FCFS algorithm.
First Come First Served(FCFS) algorithm is the CPU scheduling algorithm. In FCFS process is served when they are arrived in order, i.e First In First Out(FIFO). FCFS is the simple scheduling algorithm, but it takes typically long/varying waiting time.
Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* 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>
main()
{
int n,i,j,sum=0;
int arrv[10],ser[10],start[10];
int finish[10],wait[10],turn[10];
float avgturn=0.0,avgwait=0.0;
start[0]=0;
clrscr();
printf("Enter the number of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the arriwal and service time of %d process:",i+1);
scanf("%d%d",&arrv[i],&ser[i]);
}
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<i;j++)
sum=sum+ser[j];
start[i]=sum;
}
for(i=0;i<n;i++)
{
finish[i]=ser[i]+start[i];
wait[i]=start[i];
turn[i]=ser[i]+wait[i];
}
for(i=0;i<n;i++)
{
avgwait+=wait[i];
avgturn+=turn[i];
}
avgwait/=n;
avgturn/=n;
printf("narraival service Start Finish Wait Turnn");
for(i=0;i<n;i++)
printf("%dt%dt%dt%dt%dt%dn",arrv[i],ser[i],start[i],
finish[i],wait[i],turn[i]);
printf("nAverage waiting time=%f",avgwait);
printf("nAverage turn around time=%f",avgturn);
getch();
}
Read more Similar C Programs
C Basic

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

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

K & R C Chapter 4 Exercise Solutions.

We have already provided solutions to all the exercises in the bookC Programming Language (2nd Edition) popularly known as K & R C book.

In this blog post I will give links to all the exercises from Chapter 4 of the book for easy reference.

Chapter 4: Functions and Program Structure
    1. Exercise 4-1. Write the function strrindex(s,t) , which returns the position of the rightmost occurrence of t in s , or -1 if there is none.
      Solution to Exercise 4-1.
    1. Exercise 4-2.Extend atof to handle scientific notation of the form 123.45e-6 where a floating-point number may be followed by e or E and an optionally signed exponent.
      Solution to Exercise 4-2.
    1. Exercise 4-3.Given the basic framework, it’s straightforward to extend the calculator. Add the modulus ( % ) operator and provisions for negative numbers.
      Solution to Exercise 4-3.
    1. Exercise 4-4. Add commands to print the top element of the stack without popping, to duplicate it, and to swap the top two elements. Add a command to clear the stack.
      Solution to Exercise 4-4.
    1. Exercise 4-5. Add access to library functions like sin , exp , and pow . See <math.h> in Appendix B, Section 4.
      Solution to Exercise 4-5.
    1. Exercise 4-6. Add commands for handling variables. (It’s easy to provide twenty-six variables with single-letter names.) Add a variable for the most recently printed value.
      Solution to Exercise 4-6.
    2. Exercise 4-7. Write a routine ungets(s) that will push back an entire string onto the input. Should ungets know about buf and bufp , or should it just use ungetch ?
      Solution to Exercise 4-7.
    1. Exercise 4-8.Suppose that there will never be more than one character of pushback. Modify getch and ungetch accordingly.
      Solution to Exercise 4-8.
    1. Exercise 4-9.Our getch and ungetch do not handle a pushed-back EOF correctly. Decide what their properties ought to be if an EOF is pushed back, then implement your design
      Solution to Exercise 4-9.
    1. Exercise 4-10. An alternate organization uses getline to read an entire input line; this makes getch and ungetch unnecessary. Revise the calculator to use this approach.
      Solution to Exercise 4-10.
    1. Exercise 4-11. Modify getop so that it doesn’t need to use ungetch. Hint: use an internal static variable.
      Solution to Exercise 4-11.
    1. Exercise 4-12. Adapt the ideas of printd to write a recursive version of itoa ; that is, convert an integer into a string by calling a recursive routine.
      Solution to Exercise 4-12.
    1. Exercise 4-13. Write a recursive version of the function reverse(s) , which reverses the string s in place.
      Solution to Exercise 4-13.
  1. Exercise 4-14. Define a macro swap(t,x,y) that interchanges two arguments of type t . (Block structure will help.)
    Solution to Exercise 4-14.
You can purchase the book from here or here.

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!

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

To browse more C Programs visit this link

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

C Program to solve equations using Jordan elimination method.

Write a C Program to solve equations using Jordan elimination method.
Gauss-Jordan elimination method is used to solve the linear equations. In this method, We find the inverse matrix of the coefficients of equations by elementary row operations. Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* 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 solution( int a[][], int var );
int main()
{

int a[ 20 ][ 20 ], var, i, j, k, l;
clrcsr();
printf( "nEnter the number of variables:n" );
scanf( "%d", &var );

for ( i = 0;i < var;i++ )
{
printf( "nEnter the equation%d:n", i + 1 );

for ( j = 0;j < var;j++ )
{
printf( "Enter the coefficient of x%d:n", j + 1 );
scanf( "%d", &a[ i ][ j ] );
}

printf( "nEnter the constant:n" );
scanf( "%d", &a[ i ][ n ] );
}

solution( a, var );
return 0;
}



void solution( int a[ 20 ][ 20 ], int var )
{
int k, i, l, j;

for ( k = 0;k < var;k++ )
{
for ( i = 0;i <= var;i++ )
{
l = a[ i ][ k ];

for ( j = 0;j <= var;j++ )
{
if ( i != k )
a[ i ][ j ] = a[ k ][ k ] * a[ i ][ j ] – l * a[ k ][ j ];
}
}
}

printf( "nSolutions:" );

for ( i = 0;i < n;i++ )
{
printf( "nTHE VALUE OF x%d IS %fn", i + 1, ( float ) a[ i ][ n ] / ( float ) a[ i ][ i ] );
}

}
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 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!

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

C Program to lock file using semaphores.

Write a C Program to lock file using semaphores.
Using semaphores, We can control access to files, shared memory and other things. The basic functionality of a semaphore is that you can either set it, check it, or wait until it clears then set it (“test-n-set”). In C semaphores functions defined in the sys/sem library. Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* 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 <sys/file.h>
#include <error.h>
#include <sys/sem.h>
#define MAXBUF 100
#define KEY 1216
#define SEQFILE "seq_file"
int semid,fd;
void my_lock(int);
void my_unlock(int);
union semnum
{
int val;
struct semid_ds *buf;
short *array;
}arg;
int main()
{
int child, i,n, pid, seqno;
char buff[MAXBUF+1];
pid=getpid();
if((semid=semget(KEY, 1, IPC_CREAT | 0666))= = -1)
{
perror("semget");
exit(1);
}
arg.val=1;
if(semctl(semid,0,SETVAL,arg)<0)
perror("semctl");
if((fd=open(SEQFILE,2))<0)
{
perror("open");
exit(1);
}
pid=getpid();
for(i=0;i<2;i++)
{
my_lock(fd);
lseek(fd,01,0);
if((n=read(fd,buff,MAXBUF))<0)
{
perror("read");
exit(1);
}
printf("pid:%d, Seq no:%dn", pid, seqno);
seqno++;
sprintf(buff,"%dn", seqno);
n=strlen(buff);
lseek(fd,01,0);
if(write(fd,buff,n)!=n)
{
perror("write");
exit(1);
}
sleep(1);
my_unlock(fd);
}
}
void my_lock(int fd)
{
struct sembuff sbuf=(0, -1, 0);
if(semop(semid, &sbuf, 1)= =0)
printf("Locking: Resource…n");
else
printf("Error in Lockn");
}
void my_unlock(int fd)
{
struct sembuff sbuf=(0, 1, 0);
if(semop(semid, &sbuf, 1)= =0)
printf("UnLocking: Resource…n");
else
printf("Error in Unlockn");
}
Read more c programs
C Basic
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,

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
(c) www.c-program-example.com

C program to Encrypt and Decrypt a password

C Strings:
Write a C program to Encryption and Decryption of password.
In this program we encrypt the given string by subtracting the hex value from it. Password encryption is required for the security reason, You can use so many functions like hash or other keys to encrypt. Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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 <string.h>

void encrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] - key;
}
}

void decrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] + key;
}
}
int main()
{
char password[20] ;
printf("Enter the password: n ");
scanf("%s",password);
printf("Passwrod = %sn",password);
encrypt(password,0xFACA);
printf("Encrypted value = %sn",password);
decrypt(password,0xFACA);
printf("Decrypted value = %sn",password);
return 0;
}
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 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!

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

C Program to solve the producer consumer problem

Write a C Program to solve the producer consumer problem with two processes using semaphores.
Producer-consumer problem is the standard example of multiple process synchronization problem. The problem occurs when concurrently producer and consumer tries to fill the data and pick the data when it is full or empty. producer consumer problem is also known as bounded-buffer problem. In this program We use the semaphores, to solve the problem.Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* 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 <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>


#define NUM_LOOPS 20
int main(int argc, char* argv[])
{
int sem_set_id;
union semun sem_val;
int child_pid;
int i;
struct sembuf sem_op;
int rc;
struct timespec delay;


sem_set_id = semget(IPC_PRIVATE, 1, 0600);
if (sem_set_id == -1) {
perror("main: semget");
exit(1);
}
printf("Semaphore set created,
semaphore set id '%d'.n", sem_set_id);


sem_val.val = 0;
rc = semctl(sem_set_id, 0, SETVAL, sem_val);
child_pid = fork();
switch (child_pid) {
case -1:
perror("fork");
exit(1);
case 0:
for (i=0; i<NUM_LOOPS; i++) {
sem_op.sem_num = 0;
sem_op.sem_op = -1;
sem_op.sem_flg = 0;
semop(sem_set_id, &sem_op, 1);
printf("consumer: '%d'n", i);
fflush(stdout);
sleep(3);
}
break;
default:
for (i=0; i<NUM_LOOPS; i++)
{
printf("producer: '%d'n", i);
fflush(stdout);
sem_op.sem_num = 0;
sem_op.sem_op = 1;
sem_op.sem_flg = 0;
semop(sem_set_id, &sem_op, 1);
sleep(2);
if (rand() > 3*(RAND_MAX/4))
{
delay.tv_sec = 0;
delay.tv_nsec = 10;
nanosleep(&delay, NULL);
}
}
break;
}


return 0;
}
Read more c programs
C Basic
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,

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
(c) www.c-program-example.com

C program to implement Round Robin CPU scheduling algorithm.

Write a C program to implement Round Robin CPU scheduling algorithm.
In Round Robin scheduling algorithm, a small time slice or quantum is defined, all the tasks are kept in queue. The CPU scheduler picks the first task from the queue ,sets a timer to interrupt after one quantum, and dispatches the process. If the process is still running at the end of the quantum, the CPU is preempted and the process is added to the tail of the queue. If the process finishes before the end of the quantum, the process itself releases the CPU voluntarily. In either case, the CPU scheduler assigns the CPU to the next process in the ready queue. Every time a process is granted the CPU, a context switch occurs, which adds overhead to the process execution time. Round Robin scheduler is mainly used for the time sharing systems. Read more about C Programming Language . and read the C Programming Language (2nd Edition) by K and R.

/***********************************************************
* 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>
struct process
{
char na[20];
int at,bt,ft,tat,rem;
float ntat;
}Q[5],temp;
int rr[20],q,x,k;
main()
{
int f,r,n,i,j,tt=0,qt,t,flag,wt=0;
float awt=0,antat=0,atat=0;
clrscr();
printf("Enter the no. of jobs:");
scanf("%d",&n);
for(r=0;r<n;r++)
{
printf("Enter process name,arrival time and burst time:n");
scanf("%s%d%d",Q[r].na,&Q[r].at,&Q[r].bt);
}
printf("Enter quantum:n");
scanf("%d",&qt);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(Q[i].at>Q[j].at)
{
temp=Q[i];
Q[i]=Q[j];
Q[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
Q[i].rem=Q[i].bt;
Q[i].ft=0;
}
tt=0;
q=0;
rr[q]=0;
do
{
for(j=0;j<n;j++)
if(tt>=Q[j].at)
{
x=0;
for(k=0;k<=q;k++)
if(rr[k]==j)
x++;
if(x==0)
{
q++;
rr[q]=j;
}
}
if(q==0)
i=0;
if(Q[i].rem==0)
i++;
if(i>q)
i=(i-1)%q;
if(i<=q)
{
if(Q[i].rem>0)
{
if(Q[i].rem<qt)
{
tt+=Q[i].rem;
Q[i].rem=0;
}
else
{
tt+=qt;
Q[i].rem-=qt;
}
Q[i].ft=tt;
}
i++;
}
flag=0;
for(j=0;j<n;j++)
if(Q[j].rem>0)
flag++;
}while(flag!=0);
clrscr();
printf("nnttROUND ROBIN ALGORITHM");
printf("n***************************");
printf("nprocesses Arrival time burst time finish time tat wt ntat");
for(f=0;f<n;f++)
{
wt=Q[f].ft-Q[f].bt-Q[f].at;
Q[f].tat=Q[f].ft-Q[f].at;
Q[f].ntat=(float)Q[f].tat/Q[f].bt;
antat+=Q[f].ntat;
atat+=Q[f].tat;
awt+=wt;
printf("nt%st%dtt%dt%dt%dt%d %f",
Q[f].na,Q[f].at,Q[f].bt,Q[f].ft,Q[f].tat,wt,Q[f].ntat);
}
antat/=n;
atat/=n;
awt/=n;
printf("nAverage tat is %f",atat);
printf("nAverage normalised tat is %f",antat);
printf("n average waiting time is %f",awt);
getch(); }


Read more Similar C Programs
C Basic

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

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

C Program to demonstrate modf function.

Write a C program to demonstrate modf function.modf() defined in the C math.h library.
modf function breaks the double/float values to integral part and fractional part. 
Example: res = modf(3.142, &iptr) returns res=142 and iptr=3. Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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<math.h>
#include<conio.h>
int main()
{
double num,integral,result;
clrscr();
printf("n Enter fractional Numbern");
scanf("%lf",&num);
result = modf(num, &integral);

printf("%.4lf = %.4lf + %.4lfn", num, integral, result);

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

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

C Program to check whether two strings are anagrams of each other.

C Strings:
Write a c program to check whether two strings are anagrams of each other.
Two strings are said to be anagrams, if the characters in the strings are same in terms of numbers and value ,only arrangement or order of characters are may be different.
Example: “dfghjkl” and “lkjghdf” are anagrams of each other.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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<string.h>
# define NO_OF_CHARS 256
int Anagram(char *str1, char *str2)
{
    // Create two count arrays and initialize all values as 0
    int count1[NO_OF_CHARS] = {0};
    int count2[NO_OF_CHARS] = {0};
    int i;
    
    // For each character in input strings, increment count in
    // the corresponding count array
    for (i = 0; str1[i] && str2[i];  i++)
    {
        count1[str1[i]]++;
        count2[str2[i]]++;
    }
    
    // If both strings are of different length. Removing this condition
    // will make the program fail for strings like "aaca" and "aca"
    if (str1[i] || str2[i])
    return 0;
    
    // Compare count arrays
    for (i = 0; i < NO_OF_CHARS; i++)
    if (count1[i] != count2[i])
    return 0;

    return 1;
}
main()
{
    char str[100], str1[100];
    int flag = 0;
    
    printf("Enter first stringn");
    gets(str);
    
    printf("Enter second stringn");
    gets(str1);
    
    flag=Anagram(str, str1);
    if (flag==1)
    printf(""%s" and "%s" are anagrams.n", str, str1);
    else
    printf(""%s" and "%s" are not anagrams.n", str, str1);
    
    return 0;
}

Read more c programs
C Basic
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,

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
(c) www.c-program-example.com

C Program to check matrix is magic square or not

Write a c program to check whether the given matrix is a magic square matrix or not.

A matrix is magic square matrix, if all rows sum, columns sum and diagonals sum are equal.

Example:
8   1   6
3   5   7
4   9   2

is the magic square matrix. As you can see numbers in first row add up to 15 (8 + 1 + 6), so do the numbers of 2nd row 3 + 5 + 7. Also the number in the last row 4 + 9 + 2. Similarly, the columns all add up to the same number 15. Hence, this matrix is a magic square matrix.

The Program

#include <stdio.h>
void main() {
int A[50][50];
int i, j, M, N;
int size;
int rowsum, columnsum, diagonalsum;
int magic = 0;
printf("Enter the order of the matrix:\n");
scanf("%d %d", &M, &N);
if(M==N) {
printf("Enter the elements of matrix \n");
for(i=0; i<M; i++) {
for(j=0; j<N; j++) {
scanf("%d", &A[i][j]);
}
}
printf("\n\nMATRIX is\n");
for(i=0; i<M; i++) {
for(j=0; j<N; j++) {
printf("%3d\t", A[i][j]);
}
printf("\n");
}
// calculate diagonal sum
diagonalsum = 0;
for(i=0; i<M; i++) {
for(j=0; j<N; j++) {
if(i==j) {
diagonalsum = diagonalsum + A[i][j];
}
}
}
// calculate row sum
for(i=0; i<M; i++) {
rowsum = 0;
for(j=0; j<N; j++) {
rowsum = rowsum + A[i][j];
}
if(rowsum != diagonalsum) {
printf("\nGiven matrix is not a magic square");
return;
}
}
// calculate column sum
for(i=0; i<M; i++) {
columnsum = 0;
for(j=0; j<N; j++) {
columnsum = columnsum + A[j][i];
}
if(columnsum != diagonalsum) {
printf("\nGiven matrix is not a magic square");
return;
}
}
printf("\nGiven matrix is a magic square matrix");
} else {
printf("\n\nPlease enter the square matrix order(m=n) \n\n");
}
}
view raw magic_square.c hosted with ❤ by GitHub

Sample Output

Read more about C Programming Language and read the C Programming Language (2nd Edition). by K and R.

Related Programs

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!

To browse more C Programs visit this link

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