Construct a 10-element array. The values of its elements are: 50, 30, 20, 5, 15, 10, 90, 70, 80, and 40.
Write a program that does the following:
Use compact notation to initialize this array after you declare it. Average every other element of the array using either a "for" or a "while" loop. Not using a loop construct is NOT considered a correct answer.
2.Program 2 (p2.c)Write the code to do the following:
a.Declare three variables whose data types are "float" and their values are anything you choose. Write these values in a file called "myfloats.file" that did not exist before.
b.Read these floating numbers back from the file into the stdout (your screen)
Your output should contain a list of the three variables you used, and their average value that your program calculates. This should be done by printing a statement that states that the average of this and that variables is ... (you provide the answer).
3.(p3.c) Write a complete program to compare the lengths of two strings, the first is "I like summer time" and the second string is" Oh no, I like winter and snow". First declare the string variable, then define the strings before you do the comparison. Initialize your strings after you declare them, and then perform the comparison. Your program's output should indicate, what the two strings are, and whether the strings are equal or not.
4.(p4.c) (10 points) Write a program that does the following:
Write a program keep asking the user to guess a secret number until the user has guessed three times or gave up by typing 'q'. Suppose the secret number is 2025. If the the user typed in the correct number, prompt the user:"Congrats!!!" then quit from the program. Otherwise print out the number of times the user has tried and let the user to try again if they haven't guessed three times. If they have guessed three times, prompt the user: "You have tried 3 times and had no luck. Let me tell you the correct number:2025. Thank you for using my program. Bye byte!". Then quit the program.
5.(p5.c) Write a program which prints the following output: Consecutive integers 1 through 10, all printed on one line separated by a comma, followed by a blank line, followed by the same integers 1 through 10, this time printed in reverse order all on one line with each separated by a comma also. Not using a loop construct is NOT considered a correct answer.
6. What is the final value of x when the code is run? Assume that this code is a part of a complete code that has been compiled. (Circle the correct answer).
int x; for(; x<23; x++) {
}
23
22
0
none of the above
7. Which character ends any string (circle the correct answer)?
'.'
' '
''
'n'
8. Which of the following functions returns the total number of bytes needed for a variable that is declared as double? (circle the correct answer).
append();
strlen();
sizeof();
stradd();
Which of the following correctly declares an array of integers called somearray? (circle the correct answer).
int somearray[20];
int somearray;
somearray{20};
array somearray[20];
9-What is the element number of the last element of an array with 46 elements? (circle the correct answer).
46
45
0
Programmer-defined
If the fopen function call fails to open a file, what happens then? (circle the correct answer).
it causes a syntax error
It returns NULL
It returns stdin
It returns 0
What does the function sizeof(string) return if string is an array of 20 characters (char string[20])? (circle the correct answer).
A.20
B.21
C.0
D.1
Which of the following statements assigns the original value of y to x then y is incremented afterwards? (circle the correct answer).
A.x = ++y; B.x = x+y;
C.x = y++;
D.
If thisarray is an array of 20 characters then p=&thisarray[19] points to the __________ element of the array? (Fill in the blanks in the statement above and circile the correct answer)
A.21st
B.first
C.20th
D.none of the above
Consider this program fragment, what does it print? (circle the correct answer)
count = 0; ;
while (count < 20)
{ count = count + 1;
sum= sum + count;
}
printf("sum = %dn",sum); return 0;
Circle one
a.sum = 19
b.sum = 0
c.sum = 20
d.None of the above.
How many times does the following loop run: (circle the correct answer) for (i = 0; i < 10; i++)
{
}
once
ten
eleven
nine
What is the output of the following program? Explain your answer. #include <stdio.h int minimum (int values[ ] , int numberofelements) {
int minvalue, i;
minvalue = values[0];
for ( i = 1; i < numberofelements; ++i )
if ( values[i] < minvalue )
minvalue = values[ i ] ; return minvalue; } int main (void) { int array1[5] = { 170, -28 , 37, 26, -10 } ; int array2[7] = { 12, -45, 1, 10, 5, 31, 22 } ; int minimum (int values[ ] , int numberofelements); printf (" array1 minimum: %in", minimum (array1, 5) ); printf(" array2 minimum: %in", minimum (array2, 7) );
return 0;
}
18. What is printed by the following code? Explain your answer. #include<stdio.h
main()
{ int a = 3; int b = -1; int c = 0; int d = 4;
if ( d b && a <= c )
printf("The first expression is true!n"); if ( (a == 3 && b != 3) || (c != 0)) printf("And so is the secondn");
if ( a * b < c * d)
printf("The third is true too.n");
}
19. What will be the output of the following program? Explain your answer.
#include <stdio.h #include <string.h main() { int ; int *p; p=&a; printf ("The value of p = %dn ",*p);
printf ("The value of a = %dn", a);
}