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

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

C Program to delete a file.

Write a C Program to delete a file.
To delete a file in c, We use the remove macro, which is defined in stdio.h. remove macro takes filename with extension as its argument and deletes the file, if it is in the directory and returns the zero, if deleted successfully.
Note that deleted file does not goes to the recycle bin, it is going to delete permanently.
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>
#include<process.h>
main()
{
FILE *fp;
char filename[20];
int status;
clrscr();
printf("nEnter the file name:nn");
scanf("%s",filename);

fp = fopen(filename, r);

if(fp == NULL)
{
printf("Error: file not found! check the directory!!nn");
exit(0);
}
fclose(fp);
status = remove(file_name);

if( status == 0 )
printf("%s file deleted successfully.n",file_name);
else
{
printf("Unable to delete the filen");
perror("Error");
}

return 0;
}
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 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 draw a circle using c graphics.

Write C program to draw a circle using c graphics.
In this program we use the graphics.h library function to draw a circle. To use graphics.h, we have to install the drivers in to the the system by using the initgraph() function. In the program circle is the graphic function , which takes three parameters, first two are co-ordinates and the third one is the radius of the circle. 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 <graphics.h>

main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\TC\BGI");

circle(25, 25, 100);

getch();
closegraph();
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!

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