zoukankan      html  css  js  c++  java
  • CPT104-labs

     1 #include <stdio.h>
     2 
     3 /*structure declaration*/
     4 struct employee{
     5     char *name;
     6     int employee_id;
     7     double salary;
     8 };
     9 
    10 struct employee make(char*name,int employee_id,double salary){
    11     struct employee e={name,employee_id,salary};
    12     return e;
    13 }
    14 
    15 void print(struct employee e){
    16     printf("Name: %s
    ",e.name);
    17     printf("ID: %d
    ",e.employee_id);
    18     printf("Salary: %.2lf
    ",e.salary);
    19 }
    20 
    21 int main()
    22 {
    23     /*declare structure variable*/
    24     struct employee e1=make("John",1120,76909);
    25    /*print employee details*/
    26     print(e1);
    27     return 0;
    28 }
    Week5-Employee’s Details
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 /*structure declaration*/
     5 struct student{
     6     char *name;
     7     int id;
     8     int marks;
     9 };
    10 
    11 struct student make(char*name,int id,int marks){
    12     struct student s={name,id,marks};
    13     return s;
    14 }
    15 
    16 void print(struct student s){
    17     printf("Name: %s
    ",s.name);
    18     printf("ID: %d
    ",s.id);
    19     printf("Marks: %d
    ",s.marks);
    20 }
    21 
    22 int main()
    23 {
    24     puts("
    Displaying Information:
    ");
    25     int input;
    26     scanf("%d",&input);
    27     int i;
    28     for(i=1;i<=input;i++){
    29         char *name;int id,marks;
    30         name=(char*)malloc(sizeof(char)*15);
    31         scanf("%s%d%d",name,&id,&marks);
    32         struct student s={name,id,marks};
    33         print(s);
    34         free(name);
    35         if(i!=input)puts("");
    36     }
    37     return 0;
    38 }
    Week5-Structure Student
    Week5-Read and Print Date
     1 #include <stdio.h>
     2 #include <unistd.h>
     3 #include <sys/types.h>
     4 
     5 
     6 int main(int argc, char *argv[]){
     7     pid_t pid=fork();
     8     if(pid!=0)printf("Hello from Parent!
    ");
     9     else      printf("Hello from Child!
    ");
    10     return 0;
    11 }
    Week6-fork()system call-1
     1 #include <stdio.h>
     2 #include <unistd.h>
     3 
     4 int main(){
     5     int pid=fork();
     6     if(pid>0){
     7         puts("Parent process is created");
     8     }
     9     else if(pid==0){
    10         puts("Child process is created");
    11     }
    12     return 0;
    13 }
    Week6-fork()system call-2
     1 #include <stdio.h>
     2 #include <unistd.h>
     3 #include <stdlib.h>
     4 #include <sys/types.h>
     5 
     6 
     7 int main(int argc, char *argv[]){
     8     pid_t p=fork();
     9     if(p==0){
    10         printf("Child Process ID: %d
    ",getpid());
    11     }
    12     else{
    13         printf("Parent Process ID: %d
    ",getpid());
    14     }
    15     puts("Processes are exited and this line will not print");
    16     return 0;
    17 }
    Week6-fork()system call-3
    ~~Jason_liu O(∩_∩)O
  • 相关阅读:
    Java 网络编程的一些概念
    Java多线程之线程池
    Java多线程之线程协作
    Java多线程之线程同步
    Java 线程的基本使用
    线程的概念
    在Java中使用RabbitMQ
    Java Web
    Java 集合
    RabbitMQ的下载、安装
  • 原文地址:https://www.cnblogs.com/JasonCow/p/14859400.html
Copyright © 2011-2022 走看看