Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm to Insert Element in Array #373

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
72 changes: 40 additions & 32 deletions C Programs/Fcfs.c
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

void main(){
int i=0,n,at[100],bt[100],ct[100],tat[100],wt[100];
float totalTat =0, totalWt=0;

printf("enter the limit of process required");
scanf("%d",&n);

for(i=0;i<n;i++){

printf("enter the arrival time of %d process ",i+1);
#include <stdio.h>
int main()
{
int i,n,at[20],bt[20],ct[20],tat[20],wt[20],sum=0;
float totWT=0,totTAT=0;
printf("Enter the no:of processes:");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\nEnter arrival time of process %d :",i);
scanf("%d",&at[i]);
printf("enter the burst time of %d process",i+1);
printf("\nEnter burst time of process %d :",i);
scanf("%d",&bt[i]);
}
ct[0]= bt[0];
for(i=1;i<n;i++){
ct[i] =ct[i-1]+bt[i] ;
}

for(i=0;i<n;i++){
}

for(i=0;i<n;i++)
{
sum+=bt[i];
ct[i]=sum;
}

for(i=0;i<n;i++)
{
tat[i]=ct[i]-at[i];
totalTat += tat[i];
}
for(i=0;i<n;i++){
totTAT+=tat[i];
}

for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
totalWt += wt[i];
totWT+=wt[i];
}
printf("\nTABLE");
printf("\n-----------");
printf("\n\nP.NO\t AT\t BT\t CT\t TA\t WT");

for(i=0;i<n;i++)
{
printf("\nP%d\t %d\t %d\t %d\t %d\t %d",i,at[i],bt[i],ct[i],tat[i],wt[i]);
}
for(i=0;i<n;i++){
printf("%d %d %d %d %d %d \n",(i+1),at[i],bt[i],ct[i],tat[i],wt[i]);
}
printf("Avg tat: %f",totalTat/n);
printf("Avg wt: %f",totalWt/n);
}

printf("\nAverage Turnaround Time: %f",totTAT/n);
printf("\nAverage Waiting Time: %f\n",totWT/n);
}
37 changes: 11 additions & 26 deletions C Programs/Hary.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
#include <stdio.h>
#include <reg51.h>
void main()
{
char base_digits[16] =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
int converted_number[64];
int number_to_convert;
int next_digit, base, index=0;
printf("Decimal to other base conversion program \n");
printf("Enter a decimal number ");
scanf("%d",&number_to_convert);
printf("Enter desired base to convert: ");
scanf("%d",&base);
while (number_to_convert != 0)
{
converted_number[index] = number_to_convert % base;
number_to_convert = number_to_convert / base;
++index;
}
--index;
printf("\n\nConverted Number from base 10 to base %d= ",base);
for( ; index>=0; index--)
{
printf("%c", base_digits[converted_number[index]]);
}
printf("\n");
{
unsigned char xdata *ptr=0x4000;
unsigned char xdata *ptr1=0x401a;
int i;
for(i=0;i<5;i++)
{
*ptr1=*ptr;
ptr++;
ptr1++;
}
}
9 changes: 3 additions & 6 deletions C Programs/HelLoworld.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello, world");
printf("https://github.com/Gowrishankarvv");
return 0;
printf(" Hello, World!");

}
/* HELLO WORLD PROGRAM */
/* code by gowrishankarvv */


29 changes: 29 additions & 0 deletions C Programs/InsertElement.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

int main()
{
int arr[100];
int i, x, pos, n = 7;

for (i = 0; i < 7; i++)
arr[i] = i + 1;

for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");

x = 28;
pos = 5;
n++;

for (i = n-1; i >= pos; i--)
arr[i] = arr[i - 1];

arr[pos - 1] = x;

for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");

return 0;
}
65 changes: 32 additions & 33 deletions C Programs/MatrixTranspose.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
/*Program to print transpose of a matrix*/
#include<stdio.h>
void main()
{
int i,j,a,b;
int n[10][10];
int m[10][10];
printf("Enter number of rows and columns of matrix\n");
scanf("%d%d",&a,&b);
printf("Enter matrix\n");
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
scanf("%d",&n[i][j]);
}
}
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
m[i][j]=n[j][i];
}
}
printf("Transpose of given matrix\n");
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
printf("%d ",m[i][j]);
}
printf("\n");
}
}
void main()
{
int i,j,a,b;
int n[10][10];
int m[10][10];
printf("enter the order of the matrix \n");
scanf("%d%d",&a,&b);
printf("enter the matrix \n");
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
scanf("%d",&n[i][j]);
}
}
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
m[i][j]=n[j][i];
}
}
printf("transpose of the given matrix \n");
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
printf("%d ",m[i][j]);
}
printf("\n");
}
}
45 changes: 45 additions & 0 deletions C Programs/MergeArrays.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* C Program to Merge Two Arrays using For Loop */
#include<stdio.h>

int main()
{
int aSize, bSize, mSize, i, j;
int a[10], b[10], Merged[20];

printf("\n Please Enter the First Array Size : ");
scanf("%d", &aSize);

printf("\nPlease Enter the First Array Elements : ");
for(i = 0; i < aSize; i++)
{
scanf("%d", &a[i]);
}
printf("\n Please Enter the Second Array Size : ");
scanf("%d", &bSize);

printf("\nPlease Enter the Second Array Elements : ");
for(i = 0; i < bSize; i++)
{
scanf("%d", &b[i]);
}

for(i = 0; i < aSize; i++)
{
Merged[i] = a[i];
}

mSize = aSize + bSize;

for(i = 0, j = aSize; j < mSize && i < bSize; i++, j++)
{
Merged[j] = b[i];
}

printf("\n a[%d] Array Elements After Merging \n", mSize);
for(i = 0; i < mSize; i++)
{
printf(" %d \t ",Merged[i]);
}

return 0;
}
Loading