Pls help with this FAQ....

This is a discussion on Pls help with this FAQ.... within the C Programming forums, part of the General Programming Boards category; i have some questions which i dont really understand and unable to answer them, is it o.k. for me to ...

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

    Unhappy Pls help with this FAQ....

    i have some questions which i dont really understand and unable to answer them,
    is it o.k. for me to get the answer and explanation?
    some question has been answered, but it may be a wrong answer.
    thank you very much.

    1] Given the C code segment below, answer question i -v.

    for (I = 1; I <= 10; ++ I)
    {
    for (J = 1; J<=I; ++ J)
    printf("%i", I * J);
    printf("\n");
    }

    i) How many times does the first printf statement execute?
    ii) How many times does the second printf statement execute?
    iii) What is the final value in I?
    iv) What is the final value in J?
    v) What is the last value displayed by first printf statement?

    Answer :
    i) 9
    ii) 9
    iii) 10
    iv) 100
    v) 100

    2] State the value in x for the following arithmetic expressions.

    i) x = 17 % 5
    ii) x = 1 % 5
    iii) x = 6 + 4/2 * 4/4 + 3 * 2/2 - 1
    iv) x = 25 % 5 + 12.5 * 2/5
    v) x = 7/2

    Answer:
    i) 2
    ii)
    iii) 7
    iv) 5
    v) 3.5

    3] Given the following C statement, state the output produce. Assume count was declared earlier.

    for (count = 1; count <=10; ++(++count))
    printf("%2i", count *2);

    Answer : Error

    4] Answer questions (i) through (v) regarding an array called fractions.
    i) Define a symbolic constant SIZE to be replaced with the replacement text 10.
    ii) Declare an array fractions with SIZE elements of type float and initialise the elements to 0.
    iii) Name the fourth element from the beginning of the array.
    iv) Name the last element from the beginning of the array.
    v) Name the first element from the beginning of the array.

    5] Rewrite the following erroneous C statements.
    i) #define COUNT = 20
    ii) #include <string>
    iii) if (a=b) printf("a equal b\n");
    iv) char name[20] = Peterpan;
    v) int age[5] = {"0"};

    Answer :
    i) int COUNT = 20;
    ii)
    iii) if (a=b)
    printf("a equal b\n");
    iv) int name[20] = Peterpan;
    v) int age[5] = {0};

    6] Given the declaration below, state the output produce by the following printf statements. Indicate a space with a "."

    char item[20] = "Singapore";
    i) printf("%s"\n", item);
    ii) printf("12s\n", item);
    iii) printf("%-12s\n", item)
    iv)printf("%5s\n", item);
    v) printf("%5.5s\n", item);
    vi) printf("%6.5s\n", item);

    Answer :
    i) Singapore
    ii) Singapore............
    iii) ...Singapore
    iv) Singapore.....
    v)
    vi)

    7] Show the proper mode for opening a file in each case.
    i) Read from an existing test file but ensure that the program can make no changes.
    ii) Create a new binary file for both read and write access.
    iii) Read and write any part of an existing text file.
    iv) If a file doesn't exist, create it; otherwise allow reads and writes anywhere beyond the end of the original binary file.

    Answer :
    i)
    ii) Book=fopen("File.txt", "rw");
    iii)
    iv) ((Book=fopen("File.txt", "rw")) !=NULL)

    8] Given the following array's declaration statements, indicate whether valid or invalid.
    i) cha a[10] = "Alice";
    ii) char a[] = "Alice";
    iii) char a[10] = 'A', '1', 'i', 'c', 'e';
    iv) char a[10] = {0};
    v) char a[5] = "Alice";

    Answer :
    i) Valid
    ii) Invalid
    iii) Invalid
    iv) Valid
    v) Valid

    9] Given the following C program, indicate the output produce.
    void main (void)
    { int i = 0, x = 0;
    for (i = 1; i<20; i* = 2)
    {
    x++;
    printf("%i", x);
    }
    printf("\nx = %i", x);
    }

    Answer :
    12345
    x = 5

    10] Write a for loop that will calculate the sum of every third integer, begining with i = 2 (i.e. calculate the sum 2+5+8+11 ...) for all values of i that are less than 100.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Looks like homework

    Q1
    wrong
    right
    right
    wrong
    right
    (hint: there is a difference between ++I and I++)

    ect (but hey what do I know)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 01:17 PM
  2. FAQ Check/Lock
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-15-2002, 11:21 AM
  3. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 09:46 AM

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