Reference no: EM132245706
Assignment -
Problem 1. To make scanf( ) return an end-of-file EOF, enter ____________________________ from the keyboard.
Problem 2. Given unsigned short int ix = -65; write out the 16 bits stored in variable ix, most significant bit first.
Problem 3. What is printed to the display?
#include <stdio.h>
main( ) {
unsigned int x=17, y=24;
printf( "%d\n", (unsigned int)(x & y) );
}
Problem 4. What is printed to the display?
#include <stdio.h>
main( ) {
unsigned int x=17, y=24;
printf( "%d\n", (unsigned int)(x && y) );
}
Problem 5. What is printed to the display?
#include <stdio.h>
main( ){
int a=1,b=2;
b=a++;
printf("%d\n",b++);
}
Problem 6. What would be the output from the code segment below?
switch ( 'b' ) {
case 'a':
printf("a\n");
case 'b':
printf("b\n");
default:
printf("default");
}
Problem 7. Which statement or statements below assign zero to the variable "result" ?
(a) result = 9%3 - 1;
(b) result = 8%3 - 1;
(c) result = 2 - 6%2;
(d) result = 2 - 8%3;
(e) none of the above
Problem 8. Given the code segment below, would the printed value be positive, negative, or zero?
char v1[ ] = "abc", v2 = "abC";
printf(%d\n",strcmp(v1,v2));
Problem 9. Write down EXACTLY what is printed to the screen by the program below.
#include <stdio.h>
main( ) {
int i=2;
printf( "i/3=%4.2f\n",(float)(i/3) );
}
Problem 10. What is printed out to the screen by the following code segment?
i=2;
printf("%d\n", (i%3) ? i: 2*i);
Problem 11. Circle ALL that are true: "Every C program must contain ..".
(a) at least one #include statement.
(b) at least one return statement.
(c) at least one preprocessor directive.
(d) at least one variable.
(e) at least one main function argument.
Problem 12. What will be printed to the screen?
#include <stdio.h>
#include <string.h>
main( ) {
char s1[ ] = "star search", s2[ ] = "axqezwars";
printf("%s\n",strncpy(s2,s1,5));
}
Problem 13. What would be printed out by the program below?
#include <stdio.h>
#define Three(x) x*3
main( ){
printf("%d\n",Three(3-1));
}
Problem 14. What would be printed out by the code segment below?
float *pf;
double * pd;
printf("%d\n",sizeof(pd)-sizeof(pf));
Problem 15. What would be printed to the screen by the program below?
#include <stdio.h>
void funct(int x, int y){
x=3;
y= 2*x;
}
main( ){
int x=2,y=2;
funct(x,y);
printf("%d\n",x+y);
}
Problem 16. Write down the output produced by the following code fragment.
for (i = 2; i < 4; ++i){
for (j = 2; j < 4; ++j){
if (i > j)printf("0");
else if (i < j)printf("1");
else if(i+j==4)printf("0");
else printf("2");
}
printf("\n");
}
Problem 17. What will be printed by the program below?
#include <stdio.h>
main( ) {
signed char i = -8, j;
j = i >> 1;
printf("%d\n",j);
}
Problem 18. Write one line of code to open a file called "myfile.txt" located in the folder "myfolder" on the "D:" partition of the drive. Open the file for reading using file pointer fp.
FILE * fp;
Problem 19. Write one printf( ) statement to print out the value of a float variable x using three digits past the decimal point left-justified in a field of width 12 characters.
Problem 20. Write two program statements: one statement to read-in a word entered by the user from the keyboard, store it in v[ ], and one statement to printout the number of characters in the word.
char v[100];
printf("Please enter a word\n");
Problem 21. Write a printf( ) statement that prints the memory address where variable dx is stored to the screen.
double dx=1.0;
Problem 22. Write a function declaration for a subroutine mysub( ) that receives a FILE pointer as input and returns a float value.
Problem 23. Write a function definition for a subroutine mysub( ) that receives two strings as input and returns an integer 1 if the second string is completely contained anywhere within the first string, and that returns an integer 0 if it is not.
Problem 24. #include<stdio.h>
main(){
int a[3]={7,8,9};
int *ptr;
// Write a single statement here so that the integer_pointer ptr points to the value 8 in the integer array a[]
}
Problem 25. Write a program to:
(a) Read in a line of text entered by the user from the keyboard. The user may type in tabs, blanks spaces, and any characters whatsoever followed by the Enter key.
(b) If the line of text does not contain at least two commas, print the phrase "Data Entry Error" to the display.
(c) Note that the two commas might occur one-right-after-the-other. If the first two commas in the line of text occur one-right-after-the-other, print the phrase "Missing Field" to the display.
(d) If the first two commas in the line of text are separated by some text, print that text to the display. Note, the text between the first two commas may include tabs or blank spaces.
Attachment:- Assignment Files.rar