pls help with the correction...

This is a discussion on pls help with the correction... within the C Programming forums, part of the General Programming Boards category; hello everyone, i have some question here which i had answered , just need some help with the correction, kindly ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    Post pls help with the correction...

    hello everyone, i have some question here which i had answered , just need some help with the correction, kindly pls point out my mistake.
    with explanation will be great. thank you.

    1] Write a single C statement to accomplish eah of the following:
    i) Declare the variables c and this Variable to be of type int.
    ii) Read an integer -a from the keyboard.
    iii) Print the message "This is a C program." on two lines where the first line ends with C.
    iv) Print the message "This is easy." with each word seperated by tabs.
    v) Print the message in each of the following statements and rewrite the erroneous statements:

    Answer :
    i) int c;
    ii) scanf("%c", &c);
    iii) printf("This is a C \n program.");
    iv) printf("This \t is \t easy");
    v) printf("\n How are you?");

    2] Identify the errors in each of the following statements and rewrite the erroneous statements:
    i) printf("The value is %i\n", &number);
    ii) scanf("%i%i", &number1, number2);
    iii) if (a>7); printf("A is greater than 7");
    iv) if (c=>10) printf("C is equal or less than 10");

    Answer:
    i) printf("The value is %i", &number);
    ii)
    iii) if (a>7)
    printf("A is greater than 7");
    iv) if (c=>10)
    printf("C is equal or less than 10");

    3] Given the following statements, identify whether TRUE or FALSE.
    i) When the printf statement function is called it always begins printing at the begining of a new line. --- FALSE
    ii) All variable must be declared before they are used.--- TRUE
    iii) All variables must be given a type when they are declared.--- TRUE
    iv) C consider the variables number and NUMBER to be identical. --- FALSE
    v) The arithmetic operators *, /, %, + and - all have same level of precedence. --- FALSE
    vi) The declaration of "char x[10]" will automatically put zeroes throughout x.--- TRUE
    vii) A string variable control string can be sent to scanf as its first argument. --- FALSE
    viii) The strlen function returns the number of characters in its argument, and does count the null.--- TRUE
    ix) C cannot tell the difference betwen program and data files. --- FALSE
    x) C checks for subscripts that are out of range of an array's declared size. --- FALSE

    4] Write four different C statements that each add 1 to integer variable x.

    5] Choose the one answer which best fits the question.

    i) Enclosing something entirely within something else is called ___.
    a. nesting
    b. selection
    c. branching
    Answer: A

    ii) The selection structure ___.
    a. decides what value data will take.
    b. selects the result that is assigned to a variable.
    c.choose one of two or more modules to execute.
    Answer: C

    iii) The relational operators have ___ associatively.
    a. left-to-right
    b. right-to-left
    c. none of the above.
    Answer: A

    iv) Which of the following is not a relational operator in C?
    a. =
    b. <=
    c. =>
    Answer: B

    v) More comparisons are tied together with ___.
    a.relation operators
    b. logical operators
    c. assigment operators
    Answer: C

    vi) The ___ operaor has higher precedence.
    a. | |
    b. &&
    Answer: B

    vii) In the expression ((3<=4 | | a)&& 8 = = x), the ___ would be evaluated last.
    a. <=
    b. | |
    c. &&
    Answer: C

    viii) Which of the following is not a C reserved word?
    a. break
    b. scanf
    c. switch;
    Answer: A

    ix) The ___ stream is normally associated with the keyboard.
    a.stdin
    b. stderr
    c. conio
    Answer: C

    x) The first arguments to the print function is called the ___.
    a.control string
    b. the addrress of the variable to print
    c. file
    Answer: B

    6] Fill in the blanks for the following statements.
    i) A ___ loop begins with a do statement. Answer:--- for
    ii) A ___ loop begins with a while statement. Answer:--- while
    iii) ___ and ___ operators, which also make assigments, are often used in counting loops. Answer:
    1)=
    2)= =
    iv) One loop within another is known as ___ loops. Answer:--- nested
    v) A ___ has either True or False outcome. Answer:--- if

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1] Write a single C statement to accomplish eah of the following:

    1 - ii) is not correct. Here is the correct form:

    scanf( "%d", &c );

    Use the above link to read up on scanf if you need to.
    ------------------------------------------------------

    2 - i) this is incorrect. You do not use the & operator when using printf unless for some reason you're trying to print an address of a variable rather than the contents (value) of the variable. The same thing goes for 2-ii.

    2-iv) is incorrect. It should be:

    if( c <= 10 ) printf( "C is equal or less than 10");

    The order matters here. =< is not valid, <= is what you want. The same goes for >=

    -------------------------------------------------------

    vi) The declaration of "char x[10]" will automatically put zeroes throughout x.--- TRUE

    This is false. Unless declared using the 'static' keyword, variables are not by default given a zero value. You must do this manually. The exception to this is arrays, where if you, at declaration time, initialize one or more of the elements, the un-initialized elements will hold a zero value. Example:

    int array[4] = { 1, 2, 3 };

    In this case, the last element will have a zero for its value because it was undefined when we actually defined some of the elements. Likewise:

    int array[100] = { 0 };

    This in effect initializes the entire array to zero, by setting the first value to zer, and letting the rest "default" to zero.

    -----------------------------------------------

    vii) A string variable control string can be sent to scanf as its first argument. --- FALSE

    This is actually true. The wording of this question is poor, but in effect, this is valid:

    char *string = "%d %d %d";
    int x,y,z;

    scanf( string, &x, &y, &z );

    -----------------------------------------------

    viii) The strlen function returns the number of characters in its argument, and does count the null.--- TRUE

    False. It does not count the null.

    ---------------------------------------------------

    ix) C cannot tell the difference betwen program and data files. --- FALSE


    This is poorly worded. This is I believe is true. C doesn't care what file you try and open or write to or read from. The "difference" between a program and data file is something the operating system knows.

    ------------------------------------------------------


    4 is unanswered, but is as follows:

    x++;
    ++x;
    x += 1;
    x = x + 1;

    -------------------------------------------------------

    ii) The selection structure ___.


    What exactly is a "selection structure"? Are they talking about using an if statement or a switch or something similar? This is not a common term.

    -------------------------------------------------------

    5 - iv) is actually C. => is not valid. <= is.

    --------------------------------------------------------

    5 - viii ) 'break' is a keyword. 'scanf' is not, it is just a function name.

    --------------------------------------------------------

    5 ix ) 'stdin' is "standard input", or rather, the keyboard usually. Thus, A is correct.

    --------------------------------------------------------

    5 x ) the answer is 'A'. The first argument to 'printf' is a control string.

    --------------------------------------------------------

    6] Fill in the blanks for the following statements.


    i) A ___ loop begins with a do statement. Answer:--- for

    Actually, it's a "do while" loop.

    ---

    iii) ___ and ___ operators, which also make assigments, are often used in counting loops. Answer:
    1)=
    2)= =

    Actually, I believe they want "++" and "--".
    The "==" is an equality test, and as such, is not used to make assignments. (Usually. There is an exception, in which you combine it with a = and... we're getting off track.)

    ----

    v) A ___ has either True or False outcome. Answer:--- if

    I think they want a "conditional statement" or something similar as an answer here.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Correction, pls help...... :(
    By leena_teoh in forum C Programming
    Replies: 4
    Last Post: 03-21-2002, 09:14 PM
  2. i dont know what to do. pls. help!!!!
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 03-14-2002, 03:24 PM
  3. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 10:46 AM
  4. C programming - pls pls help me
    By sally arnold in forum C Programming
    Replies: 10
    Last Post: 01-16-2002, 04:55 AM
  5. Pls Help Me In This Question!!!
    By Joanna in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2001, 03:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21