Háskóli Íslands Véla-og iðnaðarverkfræði Hermun Verkefni 1. Sigríður Sigurðardóttir

Size: px
Start display at page:

Download "Háskóli Íslands Véla-og iðnaðarverkfræði Hermun Verkefni 1. Sigríður Sigurðardóttir"

Transcription

1 Háskóli Íslands Véla-og iðnaðarverkfræði Hermun 2006 Verkefni 1 Sigríður Sigurðardóttir sigridua@hi.is

2 1. liður Hermun endurtekin 1000 sinnum. Súlurit 180 Meðalbiðtími Fjöldi kúnna Tími [mín.] 2

3 180 Meðalfjöldi í röð Fjöldi kúnna Meðalfjöldi í röð 60 Nýting þjóns Fjöldi kúnna Nýting þjóns[%] 3

4 50 Heildarhermunartimi Fjöldi kúnna Tími[mín.] Quantile-quantile rit Meðalbiðtími QQ Plot of Sample Data versus Standard Normal 50 Meðalfjöldi í röð QQ Plot of Sample Data versus Standard Normal 60 Quantiles of Input Sample Quantiles of Input Sample Standard Normal Quantiles Standard Normal Quantiles 4

5 Nýting þjóns QQ Plot of Sample Data versus Standard Normal 1.1 Heildarhermunartími QQ Plot of Sample Data versus Standard Normal 1150 Quantiles of Input Sample Quantiles of Input Sample Standard Normal Quantiles Standard Normal Quantiles Quantile-quantile ritin sýna að nýting þjóns og heildarhermunartími fylgja normaldreifingu en meðalbiðtími og nýting þjóns ekki. Að endingu: Meðalbiðtími Meðalfjöldi í röð Nýting Heildarhermunartími þjóns Meðalgildi Miðgildi Staðalfrávik Stærsta gildi Minnsta gildi

6 2. liður Í öðrum lið er öðrum þjóni bætt við. Þá tekur þjónn nr. tvö við viðskiptavinum sem koma þegar þjónn nr. eitt er upptekinn. Hins vegar er viðskiptavinum alltaf vísað á nr. eitt ef báðir þjónar eru lausir. Súlurit 70 Meðalbiðtími Fjöldi kúnna Tími [mín.] 6

7 80 Nýting þjóns Fjöldi kúnna Nýting þjóns[%] 60 Nýting þjóns Fjöldi kúnna Nýting þjóns[%] 7

8 70 Meðalfjöldi í röð Fjöldi kúnna Meðalfjöldi í röð 60 Heildarhermunartimi Fjöldi kúnna Tími[mín.] 8

9 Quantile-quantile rit Meðalbiðtími Meðalfjöldi í röð Quantiles of Input Sample QQ Plot of Sample Data versus Standard Normal Standard Normal Quantiles Quantiles of Input Sample QQ Plot of Sample Data versus Standard Normal Standard Normal Quantiles Nýting þjóns 1 Quantiles of Input Sample QQ Plot of Sample Data versus Standard Normal Standard Normal Quantiles Heildarhermunartími Nýting þjóns 2 Quantiles of Input Sample QQ Plot of Sample Data versus Standard Normal Standard Normal Quantiles Standard Normal Quantiles Quantiles of Input Sample QQ Plot of Sample Data versus Standard Norm 9

10 Líkt og í fyrsta lið fylgja nýting þjóns og heildarhermunartími normaldreifingu en meðalbiðtími og meðalfjöldi í röð ekki. Meðalbiðtími Meðalfjöldi í Nýting Nýting Heildarhermunartí röð þjóns 1 þjóns 1 mi Meðalgildi Miðgildi Staðalfrávik Stærsta gildi Minnsta gildi Eins og sést á nýtingu þjónanna er mun meira álag á þjóni 1 enda er meira vísað á hann í þessu hermunarforriti. 3. liður Hér skal jafna álagið á þjónana. Kóði: /* External definitions for single-server queueing system. GNU GCC compile ( gcc -o mm1.exe mm1tpr.c -lm GNU C standard format style ( indent --honour-newlines -nbbo --line-length120 foo.c -o bar.c */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define Q_LIMIT 100 /* Limit on queue length. */ #define BUSY 1 /* Mnemonics for server's being busy */ 10

11 #define IDLE 0 /* and idle. */ unsigned int SEED; int next_event_type, num_custs_delayed, num_delays_required, num_events, num_in_q, server_status[3]; double area_num_in_q, area_server_status[3], mean_interarrival, mean_service, sim_time, time_arrival[q_limit + 1], time_last_event, time_next_event[4], total_of_delays, i; double urand () /* Uniform variate generation function (0 1]. */ return ((1.0 + (double) rand ()) * (1.0 / ((double) RAND_MAX + 1.0))); double expon (double mean) function. */ /* Exponential variate generation /* Return an exponential random variate with mean "mean". */ return -mean * log (urand ()); initialize () /* Initialization function. */ /* Initialize the simulation clock. */ sim_time = 0.0; /* Initialize the state variables. */ server_status[1] = IDLE; server_status[2] = IDLE; num_in_q = 0; time_last_event = 0.0; /* Initialize the statistical counters. */ num_custs_delayed = 0; total_of_delays = 0.0; area_num_in_q = 0.0; 11

12 area_server_status[1] = 0.0; area_server_status[2] = 0.0; /* Initialize event list. Since no customers are present, the departure (service completion) event is eliminated from consideration. */ time_next_event[1] = sim_time + expon (mean_interarrival); time_next_event[2] = 1.0e+30; time_next_event[3] = 1.0e+30; timing () /* Timing function. */ int i; double min_time_next_event = 1.0e+29; next_event_type = 0; /* Determine the event type of the next event to occur. */ for (i = 1; i <= num_events; ++i) if (time_next_event[i] < min_time_next_event) min_time_next_event = time_next_event[i]; next_event_type = i; /* Check to see whether the event list is empty. */ if (next_event_type == 0) /* The event list is empty, so stop the simulation. */ printf ("\nevent list empty at time %f", sim_time); exit (1); /* The event list is not empty, so advance the simulation clock. */ sim_time = min_time_next_event; 12

13 arrive () /* Arrival event function. */ double delay; int server_id; /* Schedule next arrival. */ time_next_event[1] = sim_time + expon (mean_interarrival); /* Check to see whether server is busy. */ if (server_status[1]==busy && server_status[2]==busy) /* Server is busy, so increment number of customers in queue. */ ++num_in_q; /* Check to see whether an overflow condition exists. */ if (num_in_q > Q_LIMIT) /* The queue has overflowed, so stop the simulation. */ printf ("\noverflow of the array time_arrival at"); printf (" time %f", sim_time); exit (2); /* There is still room in the queue, so store the time of arrival of the arriving customer at the (new) end of time_arrival. */ time_arrival[num_in_q] = sim_time; else if ((server_status[1]==busy && server_status[2]==idle)) server_id = 2; else if (server_status[1]==idle && server_status[2]==busy) server_id = 1; else 13

14 server_id = rand ()%2 +1 ; /* Server is idle, so arriving customer has a delay of zero. (The following two statements are for program clarity and do not affect the results of the simulation.) */ delay = 0.0; total_of_delays += delay; /* Increment the number of customers delayed, and make server busy. */ ++num_custs_delayed; server_status[server_id] = BUSY; /* Schedule a departure (service completion). */ time_next_event[server_id + 1] = sim_time + expon (mean_service); depart (int server_id) function. */ /* Departure event int i; double delay; /* Check to see whether the queue is empty. */ if (num_in_q == 0) /* The queue is empty so make the server idle and eliminate the departure (service completion) event from consideration. */ server_status[server_id] = IDLE; time_next_event[server_id+1] = 1.0e+30; else /* The queue is nonempty, so decrement the number of customers in queue. */ --num_in_q; /* Compute the delay of the customer who is beginning service and update 14

15 the total delay accumulator. */ delay = sim_time - time_arrival[1]; total_of_delays += delay; /* Increment the number of customers delayed, and schedule departure. */ ++num_custs_delayed; time_next_event[server_id+1] = sim_time + expon (mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; report () /* Report generator function. */ /* Compute and write estimates of desired measures of performance. */ printf ("%f\t", total_of_delays / num_custs_delayed); printf ("%f\t", area_num_in_q / sim_time); printf ("%f\t", area_server_status[1] / sim_time); printf ("%f\t", area_server_status[2] / sim_time); printf ("%f\n", sim_time); update_time_avg_stats () /* Update area accumulators for time-average statistics. */ double time_since_last_event; /* Compute time since last event, and update last-event-time marker. */ time_since_last_event = sim_time - time_last_event; time_last_event = sim_time; /* Update area under number-in-queue function. */ area_num_in_q += num_in_q * time_since_last_event; /* Update area under server-busy indicator function. */ 15

16 area_server_status[1] += server_status[1] * time_since_last_event; area_server_status[2] += server_status[2] * time_since_last_event; int main (int argc, char *argv[]) /* Main function. */ srand (time(null)); for(i=1;i<1000;i++) /* Read input parameters from command line arguments. */ if (5 == argc) /* convert input arguments to the double or integer */ mean_interarrival = atof (argv[1]); mean_service = atof (argv[2]); num_delays_required = atoi (argv[3]); SEED = atoi (argv[4]); else /* display some help to the user and exit */ /* printf ("usage: %s mean_interarrival mean_service num_delays_required SEED\n", argv[0]); printf ("example: %s \n", argv[0]);*/ return 1; /* Specify the number of events for the timing function. */ num_events = 3; /* Write report heading and input parameters. */ /*printf ("Single-server queueing system\n\n");*/ /*printf ("Random number seed %u\n\n", SEED);*/ /*printf ("Mean interarrival time%11.3f minutes\n\n", mean_interarrival);*/ 16

17 /*printf ("Mean service time%16.3f minutes\n\n", mean_service);*/ /*printf ("Number of customers%14d\n\n", num_delays_required);*/ /* Initialize the random number generator */ /* Initialize the simulation. */ initialize (); /* Run the simulation while more delays are still needed. */ while (num_custs_delayed < num_delays_required) /* Determine the next event. */ timing (); /* Update time-average statistical accumulators. */ update_time_avg_stats (); /* Invoke the appropriate event function. */ switch (next_event_type) case 1: arrive (); break; case 2: depart(1); break; case 3: depart(2); break; /* Invoke the report generator and end the simulation. */ report (); return 0; Byrjaði á að keyra forritið með 0.9 mín. meðalþjónustutíma Nú er jafnari nýting á þjónum 1 og 2 og álagið því nokkuð jafnt á þjónana: Meðaltal af nýtingu á þjóni 1 = Meðaltal af nýtingu á þjóni 2= Breytum meðalþjónustutíma í 0.5 mín. Fæ þá meira álag á þjón 2: Meðaltal af nýtingu á þjóni 1 = Meðaltal af nýtingu á þjóni 2=

18 4. liður 1.8 Til að sanna þetta þarf að skoða U á jöðrum bilsins, eða í 0 og 1. Ef U = 0 þá er β In U = β In 0 = Ef U = 1 þá er β In U = β In 1 = 0 En ef fallið β ln(1-u) er skoðað fæst: Er U = 0 þá er β ln(1-u) = β ln(1-0) = β ln1 = 0 Ef U = 1 þá er β ln(1-u) = β ln(1-1) = β ln0 = Því munar engu hvort við erum með β lnu eða β ln(1-u) þar eð við förum annars vegar frá óendanlegu í núll eða öfugt Kóði: /* External definitions for single-server queueing system. GNU GCC compile ( gcc -o mm1.exe mm1tpr.c -lm GNU C standard format style ( indent --honour-newlines -nbbo --line-length120 foo.c -o bar.c */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define Q_LIMIT 100 /* Limit on queue length. */ #define BUSY 1 /* Mnemonics for server's being busy */ #define IDLE 0 /* and idle. */ unsigned int SEED; int next_event_type, num_custs_delayed, num_delays_required, num_events, num_in_q, server_status; double area_num_in_q, area_server_status, mean_interarrival, mean_service, sim_time, time_arrival[q_limit + 1], time_last_event, time_next_event[3], total_of_delays; double urand () /* Uniform variate generation function (0 1]. */ 18

19 return ((1.0 + (double) rand ()) * (1.0 / ((double) RAND_MAX + 1.0))); double expon (double mean) /* Exponential variate generation function. */ /* Return an exponential random variate with mean "mean". */ return -mean * log (urand ()); initialize () /* Initialization function. */ /* Initialize the simulation clock. */ sim_time = 0.0; /* Initialize the state variables. */ server_status = IDLE; num_in_q = 0; time_last_event = 0.0; /* Initialize the statistical counters. */ num_custs_delayed = 0; total_of_delays = 0.0; area_num_in_q = 0.0; area_server_status = 0.0; /* Initialize event list. Since no customers are present, the departure (service completion) event is eliminated from consideration. */ time_next_event[1] = sim_time + expon (mean_interarrival); time_next_event[2] = 1.0e+30; timing () /* Timing function. */ int i; double min_time_next_event = 1.0e+29; next_event_type = 0; /* Determine the event type of the next event to occur. */ for (i = 1; i <= num_events; ++i) if (time_next_event[i] < min_time_next_event) min_time_next_event = time_next_event[i]; next_event_type = i; 19

20 /* Check to see whether the event list is empty. */ if (next_event_type == 0) /* The event list is empty, so stop the simulation. */ printf ("\nevent list empty at time %f", sim_time); exit (1); /* The event list is not empty, so advance the simulation clock. */ sim_time = min_time_next_event; arrive () /* Arrival event function. */ double delay; /* Schedule next arrival. */ if(sim_time <= 480) /*Læt þetta ganga í 8 klst. eða 480 mín. */ time_next_event[1] = sim_time + expon (mean_interarrival); /* Check to see whether server is busy. */ if (server_status == BUSY) /* Server is busy, so increment number of customers in queue. */ ++num_in_q; /* Check to see whether an overflow condition exists. */ if (num_in_q > Q_LIMIT) /* The queue has overflowed, so stop the simulation. */ printf ("\noverflow of the array time_arrival at"); printf (" time %f", sim_time); exit (2); /* There is still room in the queue, so store the time of arrival of the arriving customer at the (new) end of time_arrival. */ time_arrival[num_in_q] = sim_time; else 20

21 (The affect /* Server is idle, so arriving customer has a delay of zero. following two statements are for program clarity and do not the results of the simulation.) */ delay = 0.0; total_of_delays += delay; /* Increment the number of customers delayed, and make server busy. */ ++num_custs_delayed; server_status = BUSY; /* Schedule a departure (service completion). */ time_next_event[2] = sim_time + expon (mean_service); else time_next_event[1] = 1.0e+30; /* Ef hermunartíminn er kominn í 480 mín viljum við ekki fá annan arrive atburð svo við setjum tímann á næsta arrive atburði = óendanlegt */ depart () /* Departure event function. */ int i; double delay; /* Check to see whether the queue is empty. */ if (num_in_q == 0) else /* The queue is empty so make the server idle and eliminate the departure (service completion) event from consideration. */ server_status = IDLE; time_next_event[2] = 1.0e+30; /* The queue is nonempty, so decrement the number of customers in queue. */ --num_in_q; 21

22 /* Compute the delay of the customer who is beginning service and update the total delay accumulator. */ delay = sim_time - time_arrival[1]; total_of_delays += delay; /* Increment the number of customers delayed, and schedule departure. */ ++num_custs_delayed; time_next_event[2] = sim_time + expon (mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; report () /* Report generator function. */ /* Compute and write estimates of desired measures of performance. */ printf ("\n\naverage delay in queue%11.3f minutes\n\n", total_of_delays / num_custs_delayed); printf ("Average number in queue%10.3f\n\n", area_num_in_q / sim_time); printf ("Server utilization%15.3f\n\n", area_server_status / sim_time); printf ("Time simulation ended%12.3f minutes", sim_time); update_time_avg_stats () /* Update area accumulators for timeaverage statistics. */ double time_since_last_event; /* Compute time since last event, and update last-event-time marker. */ time_since_last_event = sim_time - time_last_event; time_last_event = sim_time; /* Update area under number-in-queue function. */ area_num_in_q += num_in_q * time_since_last_event; /* Update area under server-busy indicator function. */ area_server_status += server_status * time_since_last_event; 22

23 int main (int argc, char *argv[]) /* Main function. */ /* Read input parameters from command line arguments. */ if (5 == argc) /* convert input arguments to the double or integer */ mean_interarrival = atof (argv[1]); mean_service = atof (argv[2]); num_delays_required = atoi (argv[3]); SEED = atoi (argv[4]); else /* display some help to the user and exit */ printf ("usage: %s mean_interarrival mean_service num_delays_required SEED\n", argv[0]); printf ("example: %s \n", argv[0]); return 1; /* Specify the number of events for the timing function. */ num_events = 2; /* Write report heading and input parameters. */ printf ("Single-server queueing system\n\n"); printf ("Random number seed %u\n\n", SEED); printf ("Mean interarrival time%11.3f minutes\n\n", mean_interarrival); printf ("Mean service time%16.3f minutes\n\n", mean_service); printf ("Number of customers%14d\n\n", num_delays_required); /* Initialize the random number generator */ srand (SEED); /* Initialize the simulation. */ initialize (); /* Run the simulation while more delays are still needed. */ /*Nú er stöðvunarskilyrðið ekki lengur "num_custs_delayed < num_delays_required" heldur er hætt klukkan 17:00 og búið er að þjónusta alla viðskiptavini sem komu fyrir kl.17:00*/ int j = 1; while (j == 1) /* Determine the next event. */ 23

24 timing (); /* Update time-average statistical accumulators. */ update_time_avg_stats (); /* Invoke the appropriate event function. */ switch (next_event_type) case 1: arrive (); break; case 2: depart (); break; /*Viðbót*/ if ( sim_time > 480 && num_in_q == 0 && server_status == IDLE) j = 0; /* Invoke the report generator and end the simulation. */ report (); return 0; Output: Single-server queueing system Random number seed Mean interarrival time Mean service time minutes minutes Number of customers 1000 Average delay in queue minutes Average number in queue Server utilization Time simulation ended minutes 24

25 1.11 Náði ekki að leysa. Læt þó drög að lausn fylgja. Kóði: /* External definitions for single-server queueing system. GNU GCC compile ( gcc -o mm1.exe mm1tpr.c -lm GNU C standard format style ( indent --honour-newlines -nbbo --line-length120 foo.c -o bar.c */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define Q_LIMIT 2 /* Limit on queue length. */ #define BUSY 1 /* Mnemonics for server's being busy */ #define IDLE 0 /* and idle. */ unsigned int SEED; int next_event_type, num_custs_delayed, num_delays_required, num_events, num_in_q, server_status, numbalk; double area_num_in_q, area_server_status, mean_interarrival, mean_service, sim_time, time_arrival[q_limit + 1], time_last_event, time_next_event[3], total_of_delays; double urand () /* Uniform variate generation function (0 1]. */ return ((1.0 + (double) rand ()) * (1.0 / ((double) RAND_MAX + 1.0))); double expon (double mean) /* Exponential variate generation function. */ /* Return an exponential random variate with mean "mean". */ return -mean * log (urand ()); initialize () /* Initialization function. */ /* Initialize the simulation clock. */ sim_time = 0.0; /* Initialize the state variables. */ server_status = IDLE; num_in_q = 0; time_last_event = 0.0; /* Initialize the statistical counters. */ 25

26 num_custs_delayed = 0; total_of_delays = 0.0; area_num_in_q = 0.0; area_server_status = 0.0; numbalk = 0.0; /* Initialize event list. Since no customers are present, the departure (service completion) event is eliminated from consideration. */ time_next_event[1] = sim_time + expon (mean_interarrival); time_next_event[2] = 1.0e+30; timing () /* Timing function. */ int i; double min_time_next_event = 1.0e+29; next_event_type = 0; /* Determine the event type of the next event to occur. */ for (i = 1; i <= num_events; ++i) if (time_next_event[i] < min_time_next_event) min_time_next_event = time_next_event[i]; next_event_type = i; /* Check to see whether the event list is empty. */ if (next_event_type == 0) /* The event list is empty, so stop the simulation. */ printf ("\nevent list empty at time %f", sim_time); exit (1); /* The event list is not empty, so advance the simulation clock. */ sim_time = min_time_next_event; arrive () /* Arrival event function. */ double delay; /* Schedule next arrival. */ time_next_event[1] = sim_time + expon (mean_interarrival); /* Check to see whether server is busy. */ if (server_status == BUSY) 26

27 else /* Server is busy, so increment number of customers in queue. */ ++num_in_q; /* Check to see whether an overflow condition exists. */ if (num_in_q > Q_LIMIT) ++numbalk; --num_in_q; /* There is still room in the queue, so store the time of arrival of the arriving customer at the (new) end of time_arrival. */ else time_arrival[num_in_q] = sim_time; /* Server is idle, so arriving customer has a delay of zero. (The following two statements are for program clarity and do not affect the results of the simulation.) */ delay = 0.0; total_of_delays += delay; /* Increment the number of customers delayed, and make server busy. */ ++num_custs_delayed; server_status = BUSY; /* Schedule a departure (service completion). */ time_next_event[2] = sim_time + expon (mean_service); depart () /* Departure event function. */ int i; double delay; /* Check to see whether the queue is empty. */ if (num_in_q == 0) /* The queue is empty so make the server idle and eliminate the departure (service completion) event from consideration. */ server_status = IDLE; 27

28 time_next_event[2] = 1.0e+30; else /* The queue is nonempty, so decrement the number of customers in queue. */ --num_in_q; /* Compute the delay of the customer who is beginning service and update the total delay accumulator. */ delay = sim_time - time_arrival[1]; total_of_delays += delay; /* Increment the number of customers delayed, and schedule departure. */ ++num_custs_delayed; time_next_event[2] = sim_time + expon (mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; report () /* Report generator function. */ /* Compute and write estimates of desired measures of performance. */ printf ("\n\naverage delay in queue%11.3f minutes\n\n", total_of_delays / num_custs_delayed); printf ("Average number in queue%10.3f\n\n", area_num_in_q / sim_time); printf ("Server utilization%15.3f\n\n", area_server_status / sim_time); printf ("Number of balked customer\n\n", numbalk); /*Viðbót printf ("Time simulation ended%12.3f minutes", sim_time); update_time_avg_stats () /* Update area accumulators for time-average statistics. */ double time_since_last_event; /* Compute time since last event, and update last-event-time marker. */ time_since_last_event = sim_time - time_last_event; time_last_event = sim_time; /* Update area under number-in-queue function. */ area_num_in_q += num_in_q * time_since_last_event; /* Update area under server-busy indicator function. */ 28

29 area_server_status += server_status * time_since_last_event; int main (int argc, char *argv[]) /* Main function. */ /* Read input parameters from command line arguments. */ if (5 == argc) /* convert input arguments to the double or integer */ mean_interarrival = atof (argv[1]); mean_service = atof (argv[2]); num_delays_required = atoi (argv[3]); SEED = atoi (argv[4]); else /* display some help to the user and exit */ printf ("usage: %s mean_interarrival mean_service num_delays_required SEED\n", argv[0]); printf ("example: %s \n", argv[0]); return 1; /* Specify the number of events for the timing function. */ num_events = 2; /* Write report heading and input parameters. */ printf ("Single-server queueing system\n\n"); printf ("Random number seed %u\n\n", SEED); printf ("Mean interarrival time%11.3f minutes\n\n", mean_interarrival); printf ("Mean service time%16.3f minutes\n\n", mean_service); printf ("Number of customers%14d\n\n", num_delays_required); /* Initialize the random number generator */ srand (SEED); /* Initialize the simulation. */ initialize (); /* Run the simulation while more delays are still needed. */ while (sim_time <= 480) /* Determine the next event. */ timing (); /* Update time-average statistical accumulators. */ update_time_avg_stats (); 29

30 /* Invoke the appropriate event function. */ switch (next_event_type) case 1: arrive (); break; case 2: depart (); break; /* Invoke the report generator and end the simulation. */ report (); return 0; 30

Heimadæmi 7. Þorsteinn Jón Gautason Tölvunarfræði 1. Dæmi 1

Heimadæmi 7. Þorsteinn Jón Gautason Tölvunarfræði 1. Dæmi 1 Þorsteinn Jón Gautason Tölvunarfræði 1 Dæmi 1 Heimadæmi 7 Skrifið fallið int[] slembifylki(int N, int k), sem fær inn heiltölurnar N og k, býr til N-staka heiltölufylki með slembiheiltölum frá 0 til k-1,

More information

A Case Study. Objective

A Case Study. Objective A Case Study Dr. Xiao Qin New Mexico Tech http://www.cs.nmt.edu/~xqin xqin@cs.nmt.edu Fall, 2006 These slides are adapted from notes by Dr. Anirban Mahanti (U. of Calgary) CS589-6, New Mexico Tech 1 Objective

More information

>>> Assignment #4 for Simulation (CAP 4800) <<<

>>> Assignment #4 for Simulation (CAP 4800) <<< >>> Assignment #4 for Simulation (CAP 4800) > SOLUTIONS

More information

Til að athuga hvort N sé prímtala" Til að finna allar prímtölur <= N" Hægt að gera betur" Sáld Eratosþenesar"

Til að athuga hvort N sé prímtala Til að finna allar prímtölur <= N Hægt að gera betur Sáld Eratosþenesar Sáld Eratosþenesar Til að athuga hvort N sé prímtala Einfaldur kóði tekur N 1/2 aðgerðir Prufum allar tölur frá 2 N 1/2 Hægt að gera betur log(n) 7.5 Til að finna allar prímtölur

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

Heimadæmi 10. Þorsteinn Jón Gautason Tölvunarfræði 1. Dæmi 1. Skrifið fallið Powa.java. Lausn

Heimadæmi 10. Þorsteinn Jón Gautason Tölvunarfræði 1. Dæmi 1. Skrifið fallið Powa.java. Lausn Þorsteinn Jón Gautason Tölvunarfræði 1 Dæmi 1 Skrifið fallið Powa.java Lausn Heimadæmi 10 public class Powa { // skilgreinum double breyturnar n og x double n, x; // reiknum gildin og prentum þau út for

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or

More information

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10

More information

Leit er annað klassískt vandamál. Gefið fylki af heiltölum int[] a er x í fylkinu, þ.e. a[i]==x fyrir eitthvað i?!

Leit er annað klassískt vandamál. Gefið fylki af heiltölum int[] a er x í fylkinu, þ.e. a[i]==x fyrir eitthvað i?! Leit Leit er annað klassískt vandamál. Gefið fylki af heiltölum int[] a er x í fylkinu, þ.e. a[i]==x fyrir eitthvað i? Einföld lausn, leitum í fylkinu // Notkun: i = linulegleit(a,x) // Fyrir: ekkert //

More information

Fylki eru notuð til að halda utan um mikið magn gagna!! Fylki er runa gagna af sama tagi!

Fylki eru notuð til að halda utan um mikið magn gagna!! Fylki er runa gagna af sama tagi! Fylki Fylki eru notuð til að halda utan um mikið magn gagna Fylki er runa gagna af sama tagi 52 Spil í spilastokk 230 nemendur í námskeiðinu 1 milljón stafir í bók 10 milljón hljóðbylgjur í mp3 skrá 3

More information

SIMULATION OF A SINGLE-SERVER QUEUEING SYSTEM

SIMULATION OF A SINGLE-SERVER QUEUEING SYSTEM SIMULATION OF A SINGLE-SERVER QUEUEING SYSTEM Will show how to simulate a specific version of the single-server queuing system Though simple, it contains many features found in all simulation models 1-

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

Í Java getum við notað skil (interface) til að útfæra fjölbreytni og endurnýta kóða!! Tvær aðferðir í viðbót!

Í Java getum við notað skil (interface) til að útfæra fjölbreytni og endurnýta kóða!! Tvær aðferðir í viðbót! Fjölbreytni Í Java getum við notað skil (interface) til að útfæra fjölbreytni og endurnýta kóða Tvær aðferðir í viðbót Erfðir inheritance (subtyping) Sniðmát - generics Skil Dæmi: sort fallið fyrir hluti

More information

Sýnislausnir á heimadæmum 11

Sýnislausnir á heimadæmum 11 Sýnislausnir á heimadæmum 11 1. Java forrit til að búa til slembi Albers ferning: import java.awt.color; public class HHSquares { Color[] c = new Color[4]; StdDraw.setCanvasSize(500, 500); StdDraw.setXscale(0.0,

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam Lecture given by: Paolo Bientinesi First exam, 10.02.2015 The following document is a transcript from memory created

More information

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

TÖL101G - Tölvunarfræði 1 Vikublað 9 Lausn

TÖL101G - Tölvunarfræði 1 Vikublað 9 Lausn TÖL101G - Tölvunarfræði 1 Vikublað 9 Lausn Ængar 3.2.8 public class Interval { private final double left,right; // táknar bilið [left,right] ef left

More information

ECET 264 C Programming Language with Applications. C Program Control

ECET 264 C Programming Language with Applications. C Program Control ECET 264 C Programming Language with Applications Lecture 7 C Program Control Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 7 - Paul I. Lin

More information

Programming for Engineers Functions

Programming for Engineers Functions Programming for Engineers Functions ICEN 200 Spring 2018 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

Programming Assignment #3 Event Driven Simulation

Programming Assignment #3 Event Driven Simulation CS-2303, System Programming Concepts, A-term 2012 Project 3 (45 points) Assigned: Friday, September 7, 2012 Due: Friday, September 14, 2012, 11:59 PM Abstract Programming Assignment #3 Event Driven Simulation

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

VÖRUMERKJAHANDBÓK LOGO MANUAL

VÖRUMERKJAHANDBÓK LOGO MANUAL VÖRUMERKJAHANDBÓK LOGO MANUAL Efnisyfirlit Index 00 Upplýsingar 01 Merki 02 Litir 03 Svart á hvítu 04 Hvítt á svörtu 05 Það sem má ekki 06 Stærð 07 Nafnið 08 Letur 09 Slagorð 10 Svæði merkis 00 Information

More information

CS 2301 Exam 3 B-Term 2011

CS 2301 Exam 3 B-Term 2011 NAME: CS 2301 Exam 3 B-Term 2011 Questions 1-3: (15) Question 4: (15) Question 5: (20) Question 6: (10) Question 7: (15) Question 8: (15) Question 9: (10) TOTAL: (100) You may refer to one sheet of notes

More information

C: How to Program. Week /Apr/23

C: How to Program. Week /Apr/23 C: How to Program Week 9 2007/Apr/23 1 Review of Chapters 1~5 Chapter 1: Basic Concepts on Computer and Programming Chapter 2: printf and scanf (Relational Operators) keywords Chapter 3: if (if else )

More information

CSE 333 Lecture 7 - final C details

CSE 333 Lecture 7 - final C details CSE 333 Lecture 7 - final C details Steve Gribble Department of Computer Science & Engineering University of Washington Today s topics: - a few final C details header guards and other preprocessor tricks

More information

CS 6400 Lecture 11 Name:

CS 6400 Lecture 11 Name: Readers and Writers Example - Granularity Issues. Multiple concurrent readers, but exclusive access for writers. Original Textbook code with ERRORS - What are they? Lecture 11 Page 1 Corrected Textbook

More information

Debugging Techniques. CEFET Engineering Week

Debugging Techniques. CEFET Engineering Week Debugging Techniques CEFET Engineering Week Petrópolis, May 10 th 2017 Luís Tarrataca 1 Luís Tarrataca CEFET Engineering Week (Luís Tarrataca 8:00): Debugging Techniques Task 1 It is expected that course

More information

Dæmi 2. Lausn. double ymin = 0; double ymax = 100; kvarda(ymin, ymax, a); for (int i=0; i<n; i++){ System.out.print(a[i]+" "); System.out.

Dæmi 2. Lausn. double ymin = 0; double ymax = 100; kvarda(ymin, ymax, a); for (int i=0; i<n; i++){ System.out.print(a[i]+ ); System.out. Dæmi 1 Skrifið fallið dalksumma(int[][] a), sem fær inn tvívíða N xn heiltölufylkið a og skilar út einvíðu fylki með summu hvers dálks í a. Þannig inniheldur stak i í úttaksfylkinu summu talnanna í dálki

More information

At the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details.

At the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details. Objective of this lecture: At the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details. Fundamental Programming Structures in C

More information

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. Functions Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 5.1 Introduction 5.3 Math Library Functions 5.4 Functions 5.5

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

Matlab? Chapter 3-4 Matlab and IPT Basics. Working Environment. Matlab Demo. Array. Data Type. MATLAB Desktop:

Matlab? Chapter 3-4 Matlab and IPT Basics. Working Environment. Matlab Demo. Array. Data Type. MATLAB Desktop: Matlab? Lecture Slides ME 4060 Machine Vision and Vision-based Control Chapter 3-4 Matlab and IPT Basics By Dr. Debao Zhou 1 MATric LABoratory data analysis, prototype and visualization Matrix operation

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

Review of Scientific Programming in C and Fortran. Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration

Review of Scientific Programming in C and Fortran. Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration Monte Carlo Simulator Simulate by randomly generating thousands of tracks?

More information

Bristol Institute of Technology

Bristol Institute of Technology Bristol Institute of Technology Academic Year: 09/10 Module Leader: Module Code: Title of Module: Ian Johnson UFCETS-20-1 Programming in C Examination Date: Monday 12 th January 2009 Examination Start

More information

ECE SPRING NOTE; This project has two parts which have different due dates.

ECE SPRING NOTE; This project has two parts which have different due dates. DATA STRUCTURES ECE 368 - SPRING 208 PROJECT : Event Driven Simulation for a Multiprocessor System Using a Priority Queue (It is a team project. Note: 2 students/team) ASSIGNMENT DATE: January 23, 208

More information

ECE264 Spring 2013 Exam 1, February 14, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013 ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Text Output and Input; Redirection

Text Output and Input; Redirection Text Output and Input; Redirection see K&R, chapter 7 Simple Output puts(), putc(), printf() 1 Simple Output The simplest form of output is ASCII text. ASCII occurs as single characters, and as nullterminated

More information

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013 Problem 1 (3 parts, 30 points) Code Fragments Part A (5 points) Write a MIPS code fragment that branches to label Target when register $1 is less than or equal to register $2. You may use only two instructions.

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üc is a procedural language üeach function performs a certain task A special

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015 Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 1 Wednesday, February 11, 2015 Marking Exemplar Duration of examination: 75

More information

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? Overview For this lab, you will use: one or more of the conditional statements explained below scanf()

More information

Variables and literals

Variables and literals Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

More information

Chapter 14 - Advanced C Topics

Chapter 14 - Advanced C Topics Chapter 14 - Advanced C Topics Outline 14.1 Introduction 14.2 Redirecting Input/Output on UNIX and DOS Systems 14.3 Variable-Length Argument Lists 14.4 Using Command-Line Arguments 14.5 Notes on Compiling

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Simple Output and Input. see chapter 7

Simple Output and Input. see chapter 7 Simple Output and Input see chapter 7 Simple Output puts(), putc(), printf() Simple Output The simplest form of output is ASCII text. ASCII occurs as single characters, and as nullterminated text strings

More information

Íslenskur fjarskiptamarkaður í tölum / Data collection

Íslenskur fjarskiptamarkaður í tölum / Data collection Íslenskur fjarskiptamarkaður í tölum / Data collection Tafla 1. Fjarskiptafyrirtæki 1997 25 Table 1. Telecommunications operators 1997 25 1997 1998 1999 2 21 22 23 24 3 25 Almenna símanetið (Fixed network

More information

Assoc. Prof. Dr. Tansu FİLİK

Assoc. Prof. Dr. Tansu FİLİK Assoc. Prof. Dr. Tansu FİLİK Computer Programming Previously on Bil 200 Midterm Exam - 1 Midterm Exam - 1 126 students Curve: 49,78 Computer Programming Arrays Arrays List of variables: [ ] Computer Programming

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

Sample Problems for Quiz # 3

Sample Problems for Quiz # 3 EE 1301 UMN Introduction to Computing Sstems Spring 2013 Sample Problems for Quiz # 3 1. Implementing XOR with AND gates Recall that the Eclusive-OR (XOR) function is 1 if an odd number of the inputs are

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39 Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis EL2310 Scientific Programming LAB2: C lab session Patric Jensfelt, Andrzej Pronobis Chapter 1 Introduction 1.1 Reporting errors As any document, this document is likely to include errors and typos. Please

More information

C-String Library Functions

C-String Library Functions Strings Class 34 C-String Library Functions there are several useful functions in the cstring library strlen: the number of characters before the \0 strncat: concatenate two strings together strncpy: overwrite

More information

Gistiskýrslur - Schema

Gistiskýrslur - Schema Statistics Iceland Borgartúni 21a IS-105 Reykjavík Iceland Gistiskýrslur - Schema Last updated: 13.2.2017 Owner Statistics Iceland Version 2.00 Author Sigurður Marísson sigurdur.marisson@statice.is Table

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

Chapter 4 Functions By C.K. Liang

Chapter 4 Functions By C.K. Liang 1 Chapter 4 Functions By C.K. Liang What you should learn? 2 To construct programs modularly from small pieces called functions Math functions in C standard library Create new functions Pass information

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,

More information

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point

More information

Computer Systems Lecture 9

Computer Systems Lecture 9 Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

More information

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

More information

C0MP1911 Final Exam 1337 Computing 1

C0MP1911 Final Exam 1337 Computing 1 Family Name: Other Names: Signature: Student Number: This PAPER is NOT to be retained by the STUDENT The University Of New South Wales C0MP1911 Final Exam 1337 Computing 1 July 2006 Time allowed: 3 hrs

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 11: Memory, Files and Bitoperations (yaseminb@kth.se) Overview Overview Lecture 11: Memory, Files and Bit operations Main function; reading and writing Bitwise Operations Lecture 11: Memory, Files

More information

File: /home/young/mywork/5.cordic_vhdl/f.c/lut.src.print Page 1 of 9

File: /home/young/mywork/5.cordic_vhdl/f.c/lut.src.print Page 1 of 9 File: /home/young/mywork/5.cordic_vhdl/f.c/lut.src.print Page 1 of 9 makefile.suffixes :.o.cpp.c.cpp.o : g++ -c -g -I${HOME/include $

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm Operating Systems Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) armahmood786@yahoo.com alphasecure@gmail.com alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net pk.linkedin.com/in/armahmood

More information

Random Number Generation. Biostatistics 615/815 Lecture 16

Random Number Generation. Biostatistics 615/815 Lecture 16 Random Number Generation Biostatistics 615/815 Lecture 16 Some Uses of Random Numbers Simulating data Evaluate statistical procedures Evaluate study designs Evaluate program implementations Controlling

More information

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy

More information

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3 Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running

More information

Basic Assignment and Arithmetic Operators

Basic Assignment and Arithmetic Operators C Programming 1 Basic Assignment and Arithmetic Operators C Programming 2 Assignment Operator = int count ; count = 10 ; The first line declares the variable count. In the second line an assignment operator

More information

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

Advanced Pointer Topics

Advanced Pointer Topics Advanced Pointer Topics Pointers to Pointers A pointer variable is a variable that takes some memory address as its value. Therefore, you can have another pointer pointing to it. int x; int * px; int **

More information

Review Topics. Final Exam Review Slides

Review Topics. Final Exam Review Slides Review Topics Final Exam Review Slides!! Transistors and Gates! Combinational Logic! LC-3 Programming!! Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox,

More information

ESC101N: Fundamentals of Computing End-sem st semester

ESC101N: Fundamentals of Computing End-sem st semester ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information