Correction, pls help...... :(

This is a discussion on Correction, pls help...... :( within the C Programming forums, part of the General Programming Boards category; 1] Given the C code segment below, answer question i -v. for (I = 1; I <= 10; ++ I) ...

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

    Post Correction, pls help...... :(

    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
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    aaaaaaaaawwwwwwwww, I smell homework. If we tell you then you may as well throw away the book and don't go to class again. Just take advantage of us.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    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: Go to another school, preferably one where the teachers know that void main is WRONG!

    -Prelude
    My best code is written with the delete key.

  4. #4
    unregistered
    Guest
    Which school is the homework from??

    Some polytechnic from Singapore?

    Sure looks like you need alot of help there....

  5. #5
    Unregistered
    Guest
    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

    I'm sure its for homework but what the hell.

    int main()
    {
    int counter, sum=0;

    for(counter=2;counter<100;counter+=3)
    sum+=counter;
    printf("Total Value: %d",sum);
    return 1;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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