NetId:
____________________________
Section: _____________
Print out this page and fill in the blanks to answer the following questions. Hand in this assignment at the beginning of Lab 10. As with all prelabs/labs, if you are not sure of the answer you may go to any EWS lab on campus and check your results by using the gcc compiler, or you can ask anyone of the CS101 staff for help.
The following exercises should help prepare you for the in-lab activities and MP2. You will use the C loop statements (while, do-while,for) and arrays.#include <stdio.h>
void main(void){
int i,j;
int temp;
int x[3] = { 3, 4, 1};
/* bubbles(smaller values) float up(move to the beginning of the array) */
for(j=3; j > 1; j=j-1)
for(i=0; i < j-1; i=i+1)
if(x[i] > x[i+1])
{
/* swap */
temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
}
for(i=0; i< 3; i=i+1)
printf("%i ",x[i]);
printf("\n");
}
__________________________________________________________________________
#include <stdio.h>_____________________________________
void main(void)
{
char string1[] = {'H','e','l','l','o','\n'};
char string2[] = "Hello";
int result = strcmp(string1,string2);
if (result == 0)
printf("Equal!");
else
printf("Not equal!");
printf("\n");
if( strcmp("Hello", string2) == 0)
printf("Equal!");
else
printf("Not equal!");
printf("\n");
}
int i,total = 0;
int scores[40];
double average;
/* some code not shown here that assigns values to the scores array */
for(i=0; _____________________; ____________________ ) {
______________________________________;
}
average = __________________________________;
min = scores[0];
for(i=1; ___________________; ________________________ ) {
if ( ___________________ scores[i] )
min = ____________________________;
}
printf("The lowest score is %i.\n",min);
#include <stdio.h>
void main(void)
{
char fname[72];
char greeting[132];
printf("Enter your first name: ");
scanf("%s", ________________________________);
strcpy(greeting , "Hello ");
strcat(greeting , _______________________________________);
strcat(greeting , " !");
printf(" %s \n", greeting);
}
#include <stdio.h>_______________________________________
void main(void)
{
char password[32] = "CS101";
char course[32] = {'C','S','1','\0','5'};
printf("%s \n", password);
printf("%s \n", course);
printf("%c \n",password[1]);
strcpy(password, course);
printf("%s \n", password);
if (strcmp( password, "CS101") > 0)
printf("yes \n");
else
printf("no \n");
}