Computer science (sometimes called computation science) is the study of processes that interact with data and that can be represented as data in the form of programs. It enables the use of algorithms to manipulate, store, and communicate digital information. A computer scientist studies the theory of computation and the practice of designing software systems. UGC care journals in Computer science, Its fields can be divided into theoretical and practical disciplines. Computational complexity theory is highly abstract, while computer graphics emphasizes real-world applications. Programming language theory considers approaches to the description of computational processes, while software engineering involves the use of programming languages and complex systems. Human–computer interaction considers the challenges in making computers useful, usable, and accessible.
while (read(handle, &ch, 1) > 0) { if (ch == '\n' || j == sizeof(buffer) - 1) { buffer[j] = '\0'; // End current line j = 0; // Reset buffer index
if (strstr(buffer, searchStr)) { if (mode == 'f') { printf("%d : %s\n", i, buffer); break; } else if (mode == 'c') { count++; } else if (mode == 'a') { printf("%d : %s\n", i, buffer); } } i++; // Line number increment } else { buffer[j++] = ch; // Store character in buffer } }
if (mode == 'c') { printf("Total No. of Occurrences = %d\n", count); }
close(handle); }
int main() { char cmd[80], searchStr[20], filename[20], mode;
while (1) { printf("myShell$ "); fgets(cmd, sizeof(cmd), stdin);
Slot-I Write an MPI program to calculate sum of randomly generated 1000 numbers(stored in array)on a cluster. #include #include #include #include #define SIZE 1000 int main(int argc, char *argv[]) { int rank, size; int num[SIZE]; int l_sum = 0, t_sum = 0; //local sum and total sum int c_size; //chucnk sizeMPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); c_size = SIZE / size; // Process 0 generates the random numbers if (rank == 0) { srand(time(NULL)); for (int i = 0; i < SIZE; i++) { num[i] = rand() % 100; } } // Scatter the numbers to all processes int *l_num = malloc(c_size * sizeof(int));// local_numbers MPI_Scatter(num, c_size, MPI_INT,l_num, c_size, MPI_INT,0, MPI_COMM_WORLD); // Each process computes its local sum for (int i = 0; i < c_size; i++) { l_sum += l_num[i]; } // Gather the local sums and add them together MPI_Reduce(&l_sum, &t_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); // Process 0 prints the final result if (rank == 0) { printf("Total sum of 1000 random numbers: %d\n", t_sum); } // Free memory and finalize MPI free(l_num); MPI_Finalize(); return 0; }Slot-II Write an MPI program to find the min and min number from randomly generated 1000 numbers(stored in array)on a cluster. #include #include #include #include #define SIZE 1000 int main(int argc, char *argv[]) { int rank, size; int num[SIZE]; int l_min, l_max, g_min, g_max; //local_min, local_max, global_min, global_max int c_size; //chunk sizwee MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); c_size = SIZE / size; // Process 0 generates the random numbers if (rank == 0) { srand(time(NULL)); for (int i = 0; i < SIZE; i++) { num[i] = rand() % 1000; // Random numbers between 0 and 999 } } // Scatter the numbers to all processes int *l_num = malloc(c_size * sizeof(int)); // local_numberss MPI_Scatter(num, c_size, MPI_INT, l_num, c_size, MPI_INT, 0, MPI_COMM_WORLD); // Each process finds its local min and maxl_min = l_num[0]; l_max = l_num[0]; for (int i = 1; i < c_size; i++) { if (l_num[i] < l_min) l_min = l_num[i]; if (l_num[i] > l_max) l_max = l_num[i]; } // Use MPI_Reduce to find global min and max MPI_Reduce(&l_min, &g_min, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(&l_max, &g_max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD); // Process 0 prints the final min and max if (rank == 0) { printf("Minimum number: %d\n", g_min); printf("Maximum number: %d\n", g_max); } // Free memory and finalize MPI free(l_num); MPI_Finalize(); return 0; }
23 Comments
This comment has been removed by the author.
ReplyDeleteComputer science (sometimes called computation science) is the study of processes that interact with data and that can be represented as data in the form of programs. It enables the use of algorithms to manipulate, store, and communicate digital information. A computer scientist studies the theory of computation and the practice of designing software systems.
ReplyDeleteUGC care journals in Computer science,
Its fields can be divided into theoretical and practical disciplines. Computational complexity theory is highly abstract, while computer graphics emphasizes real-world applications. Programming language theory considers approaches to the description of computational processes, while software engineering involves the use of programming languages and complex systems. Human–computer interaction considers the challenges in making computers useful, usable, and accessible.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteتصميم المواقع أفضل الممارسات التي يقوم بها أصحاب الأعمال اليوم يمكنك الأن
ReplyDeleteتصميم مواقع
تصميم متجر الكتروني
You can explore more than 100+ C programs on code forever C programs
ReplyDeleteSAP Basis Training In Noida
ReplyDeleteNice Blog. Thanks for sharing very useful blog for students. It will be really helpful.
ReplyDeleteWhich is the best College in India and branch to do M.Sc after completing B.Sc in Agriculture?
What is the difference between BSc IT and BSc computer science?
Which is better: BCA or B.Sc (PCM)?
What is the future scope of BSc in agriculture?
Importance of career guidance for B.Sc. Agriculture graduates
FYBCS COMPUTER SCIENCE: https://scitechexplorer.com/fybcs
ReplyDeleteFCFS algo
ReplyDelete#include
#include
#include
struct job
{
char name[20];
int at,bt,ct,tat,wt,st,tbt;
}job[10];
int n,i,j;
float avg_tat=0;
float avg_wt=0;
void take_input()
{
printf("Enter the no of jobs : ");
scanf("%d",&n);
for(i=0;ijob[j].at)
{
temp=job[i];
job[i]=job[j];
job[j]=temp;
}
}
}
}
// to calculate the tat n wt
void process()
{
int time=job[0].at;
for(j=0;j<n;j++)
{
job[j].st=time;
printf("| %d %s ",job[j].st,job[j].name);
time=time+job[j].tbt;
job[j].ct = time;
job[j].tat=time-job[j].at;
job[j].wt=job[j].tat-job[j].tbt;
printf("%d |",time);
}
}
//to print the output table
void print_output()
{
printf("\n\n");
printf("\n---------------------------------------");
printf("\n PName AT BT TAT WT ");
printf("\n---------------------------------------");
for(i=0;i<n;i++)
{
printf("\n%s %d %d %d %d",job[i].name,job[i].at,job[i].bt,job[i].tat,job[i].wt);
avg_tat=avg_tat+(float)(job[i].tat);
avg_wt=(float)avg_wt+(float)(job[i].wt);
}
printf("\n-----------------------------------------");
printf("\nTheavg of the Turn Around Time is %f",avg_tat/n);
printf("\nTheavg of the Waiting Time is %f",avg_wt/n);
}
int main()
{
int i;
take_input();
sort();
process();
print_output();
printf("\n\n");
for(i=0;i<n;i++)
{
//job[i].tbt=job[i].bt=rand()%10+1;
job[i].at=job[i].ct+2;
}
process();
print_output();
}
LFU
ReplyDelete#include
#define frame 3
int mem[frame][2]={-1,0,-1,0,-1,0};
int pagefault=0;
int n=15;
int a[]={7,3,5,8,5,8,3,6,7,3,6,7,8,5,3};
void mfu(int p)
{
int k,f=0;
for(k=0;k<frame;k++)
{
if(mem[k][0]==p)
{
mem[k][1]=mem[k][1]+1;
return;
}
}
printf("\n\n Page fault");
pagefault++;
for(k=0;k<frame;k++)
if(mem[k][0]==-1)
{
mem[k][0]=p;
mem[k][1]=0;
return;
}
for(k=0;k<frame;k++)
if(mem[k][1]<mem[f][1])
f=k;
mem[f][0]=p;
mem[f][1]=0;
}
main()
{
int i=0,k;
for(i=0;i<n;i++)
{
mfu(a[i]);
for(k=0;k<frame;k++)
printf("%2d",mem[k][0]);
printf("\n\n");
}
printf("\nTotal No of Pagefault : %d",pagefault);
}
MRU
ReplyDelete#include
#include
typedef struct queue
{
int data;
struct queue *next;
}Node;
Node *start=NULL,*last=NULL;
int pgfault=0,n,nof;
int a[80];
int n1;
main()
{
int i;
printf("\nHow many Frames\t");
scanf("%d",&n);
printf("\n\nEnter the no of page\t");
scanf("%d",&n1);
for(i=0;inext)
if(ptr->data==page)
return 1;
return 0;
}
void print()
{
Node *ptr;
for(ptr=start;ptr!=NULL;ptr=ptr->next)
printf("%d\t",ptr->data);
printf("\n");
}
void addlist(int page)
{
Node *ptr=NULL;
static int cnt=0;
ptr=(Node *)malloc(sizeof(Node));
ptr->data=page;
ptr->next=NULL;
if(start==NULL)
{
start=last=ptr;
cnt++;
}
else if(cntnext=ptr;
last=ptr;
last->next=NULL;
cnt++;
}
else
{
// start=start->next;
// last->next=ptr;
last->data=ptr->data;
}
}
#include
ReplyDelete#include
typedef struct queue
{
int data;
struct queue *next;
}Node;
Node *start=NULL,*last=NULL;
int pgfault=0,n,nof;
int a[80];
int n1;
main()
{
int i;
printf("\nHow many Frames\t");
scanf("%d",&n);
printf("\n\nEnter the no of page\t");
scanf("%d",&n1);
for(i=0;inext)
if(ptr->data==page)
return 1;
return 0;
}
void print()
{
Node *ptr;
for(ptr=start;ptr!=NULL;ptr=ptr->next)
printf("%d\t",ptr->data);
printf("\n");
}
void addlist(int page)
{
Node *ptr=NULL;
static int cnt=0;
ptr=(Node *)malloc(sizeof(Node));
ptr->data=page;
ptr->next=NULL;
if(start==NULL)
{
start=last=ptr;
cnt++;
}
else if(cntnext=ptr;
last=ptr;
last->next=NULL;
cnt++;
}
else
{
last->data=ptr->data;
}
}
Search shell
ReplyDelete#include
#include
#include
#include
#include
void search(char mode, char *searchStr, char *filename) {
int handle, i = 1, count = 0, j = 0;
char ch, buffer[80];
if ((handle = open(filename, O_RDONLY)) == -1) {
perror("Error opening file");
return;
}
while (read(handle, &ch, 1) > 0) {
if (ch == '\n' || j == sizeof(buffer) - 1) {
buffer[j] = '\0'; // End current line
j = 0; // Reset buffer index
if (strstr(buffer, searchStr)) {
if (mode == 'f') {
printf("%d : %s\n", i, buffer);
break;
} else if (mode == 'c') {
count++;
} else if (mode == 'a') {
printf("%d : %s\n", i, buffer);
}
}
i++; // Line number increment
} else {
buffer[j++] = ch; // Store character in buffer
}
}
if (mode == 'c') {
printf("Total No. of Occurrences = %d\n", count);
}
close(handle);
}
int main() {
char cmd[80], searchStr[20], filename[20], mode;
while (1) {
printf("myShell$ ");
fgets(cmd, sizeof(cmd), stdin);
if (sscanf(cmd, "search %c %s %s", &mode, filename, searchStr) == 3) {
search(mode, searchStr, filename);
} else if (strcmp(cmd, "exit\n") == 0) {
break;
} else {
printf("Usage: search \n");
}
}
return 0;
}
Count shell
ReplyDelete#include
#include
#include
#include
#include
// Function to count characters, words, or lines in a file
void count(char c, char *fn) {
int lc = 0, wc = 0, cc = 0, handle;
char ch;
handle = open(fn, O_RDONLY);
while (read(handle, &ch, 1) > 0) {
cc++;
if (ch == ' ' || ch == '\n') wc++;
if (ch == '\n') lc++;
}
close(handle);
if (c == 'c') printf("Total No. of Characters = %d\n", cc);
else if (c == 'w') printf("Total No. of Words = %d\n", wc);
else if (c == 'l') printf("Total No. of Lines = %d\n", lc);
}
int main() {
char cmd[80], s[20], fn[20];
while (1) {
printf("myShell$ ");
fgets(cmd, 80, stdin);
if (sscanf(cmd, "count %s %s", s, fn) == 2) count(s[0], fn);
else if (strcmp(cmd, "exit\n") == 0) break;
else printf("Usage: count \n");
}
return 0;
}
Typeline shell
ReplyDelete#include
#include
#include
#include
#include
#include
void typeline(char *s, char *fn)
{
int handle = open(fn, O_RDONLY);
if (strcmp(s, "a") == 0)
{
char ch;
while (read(handle, &ch, 1) > 0) putchar(ch);
}
else
{
int n = atoi(s);
char ch;
int lc = 0;
if (n > 0)
{
while (read(handle, &ch, 1) > 0 && lc < n)
{
putchar(ch);
if (ch == '\n') lc++;
}
}
else
{
// Count total lines
int tl = 0;
lseek(handle, 0, SEEK_SET);
while (read(handle, &ch, 1) > 0)
{
if (ch == '\n')
tl++;
}
lseek(handle, 0, SEEK_SET); // Reset file offset
// Skip lines and print the rest
lc = tl + n; // Calculate lines to skip
while (read(handle, &ch, 1) > 0)
{
if (lc <= 0)
putchar(ch);
if (ch == '\n')
lc--;
}
}
}
close(handle);
}
int main()
{
char cmd[80], o[20], fn[20];
while (1)
{
printf("myShell$ ");
fgets(cmd, /*sizeof(cmd)*/80, stdin);
if (sscanf(cmd, "typeline %s %s", o, fn) == 2) typeline(o, fn);
else if (strcmp(cmd, "exit\n") == 0) break;
else printf("Usage: typeline \n");
}
}
Typeline
ReplyDelete#include stdlib.h
#include string.h
#include unistd.h
#include fcntl.h
#include sys/types.h
include unistd.h
ReplyDelete#include fcntl.h
#include string.h
#include stdlib.h
printf("Usage: search f/c/a<string filename \n");
ReplyDeleteCount
ReplyDelete#include stdio.h
#include stdlib.h
#include string.h
#include unistd.h
#include fcntl.h
else printf("Usage: count c/w/l filename\n");
ReplyDeleteelse printf("Usage: typeline n/a filename\n");
ReplyDeleteSlot-I
ReplyDeleteWrite an MPI program to calculate sum of randomly generated
1000 numbers(stored in array)on a cluster.
#include
#include
#include
#include
#define SIZE 1000
int main(int argc, char *argv[])
{
int rank, size;
int num[SIZE];
int l_sum = 0, t_sum = 0; //local sum and total sum
int c_size; //chucnk sizeMPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
c_size = SIZE / size;
// Process 0 generates the random numbers
if (rank == 0)
{
srand(time(NULL));
for (int i = 0; i < SIZE; i++)
{
num[i] = rand() % 100;
}
}
// Scatter the numbers to all processes
int *l_num = malloc(c_size * sizeof(int));// local_numbers
MPI_Scatter(num, c_size, MPI_INT,l_num, c_size, MPI_INT,0,
MPI_COMM_WORLD);
// Each process computes its local sum
for (int i = 0; i < c_size; i++)
{
l_sum += l_num[i];
}
// Gather the local sums and add them together
MPI_Reduce(&l_sum, &t_sum, 1, MPI_INT, MPI_SUM, 0,
MPI_COMM_WORLD);
// Process 0 prints the final result
if (rank == 0)
{
printf("Total sum of 1000 random numbers: %d\n", t_sum);
}
// Free memory and finalize MPI
free(l_num);
MPI_Finalize();
return 0;
}Slot-II
Write an MPI program to find the min and min number from
randomly generated 1000 numbers(stored in array)on a cluster.
#include
#include
#include
#include
#define SIZE 1000
int main(int argc, char *argv[])
{
int rank, size;
int num[SIZE];
int l_min, l_max, g_min, g_max; //local_min, local_max, global_min,
global_max
int c_size; //chunk sizwee
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
c_size = SIZE / size;
// Process 0 generates the random numbers
if (rank == 0)
{
srand(time(NULL));
for (int i = 0; i < SIZE; i++)
{
num[i] = rand() % 1000; // Random numbers between 0 and 999
}
}
// Scatter the numbers to all processes
int *l_num = malloc(c_size * sizeof(int)); // local_numberss
MPI_Scatter(num, c_size, MPI_INT, l_num, c_size, MPI_INT, 0,
MPI_COMM_WORLD);
// Each process finds its local min and maxl_min = l_num[0];
l_max = l_num[0];
for (int i = 1; i < c_size; i++)
{
if (l_num[i] < l_min) l_min = l_num[i];
if (l_num[i] > l_max) l_max = l_num[i];
}
// Use MPI_Reduce to find global min and max
MPI_Reduce(&l_min, &g_min, 1, MPI_INT, MPI_MIN, 0,
MPI_COMM_WORLD);
MPI_Reduce(&l_max, &g_max, 1, MPI_INT, MPI_MAX, 0,
MPI_COMM_WORLD);
// Process 0 prints the final min and max
if (rank == 0)
{
printf("Minimum number: %d\n", g_min);
printf("Maximum number: %d\n", g_max);
}
// Free memory and finalize MPI
free(l_num);
MPI_Finalize();
return 0;
}