FYBCS C Program

Post a Comment

22 Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. 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.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. تصميم المواقع أفضل الممارسات التي يقوم بها أصحاب الأعمال اليوم يمكنك الأن
    تصميم مواقع
    تصميم متجر الكتروني

    ReplyDelete
  6. You can explore more than 100+ C programs on code forever C programs

    ReplyDelete
  7. FYBCS COMPUTER SCIENCE: https://scitechexplorer.com/fybcs

    ReplyDelete
  8. FCFS algo

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

    ReplyDelete
  9. LFU


    #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);
    }

    ReplyDelete
  10. MRU
    #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;

    }

    }

    ReplyDelete
  11. #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
    {
    last->data=ptr->data;
    }
    }

    ReplyDelete
  12. Search shell


    #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;
    }

    ReplyDelete
  13. Count shell

    #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;
    }

    ReplyDelete
  14. Typeline shell


    #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");
    }
    }

    ReplyDelete
  15. Typeline


    #include stdlib.h
    #include string.h
    #include unistd.h
    #include fcntl.h
    #include sys/types.h

    ReplyDelete
  16. include unistd.h
    #include fcntl.h
    #include string.h
    #include stdlib.h

    ReplyDelete
  17. printf("Usage: search f/c/a<string filename \n");

    ReplyDelete
  18. Count

    #include stdio.h
    #include stdlib.h
    #include string.h
    #include unistd.h
    #include fcntl.h

    ReplyDelete
  19. else printf("Usage: count c/w/l filename\n");

    ReplyDelete
  20. else printf("Usage: typeline n/a filename\n");

    ReplyDelete