Submitted by tushar pramanick on Tue, 03/05/2013 - 19:36

To help you solidify your understanding of this hour's lesson, you are encouraged to try to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

 

 Do the following two for loops have the same number of iterations?

    for (j=0; j<8; j++);
    for (k=1; k<=8; k++);


    Is the following for loop

    for (j=65; j<72; j++) printf("%c", j);
    int k = 65;
    while (k<72)
        printf("%c", k);
        k++;
    }


    Can the following while loop print out anything?

    int k = 100;
    while (k<100){
        printf("%c", k);
        k++;
    }


    Can the following do-while loop print out anything?

    int k = 100;
    do {
        printf("%c", k);
        k++;
    } while (k<100);


 

 

Exercises

    What is the difference between the following two pieces of code?

    for (i=0, j=1; i<8; i++, j++)
         printf("%d  +  %d  =  %d\n", i, j, i+j);
    for (i=0, j=1; i<8; i++, j++);
         printf("%d  +  %d  =  %d\n", i, j, i+j);


    Write a program that contains the two pieces of code shown in exercise 1, and then execute the program. What are you going to see on the screen?
    Rewrite the program in Listing 7.4. This time, you want the for statement to keep looping until the user enters the character K.
    Rewrite the program in Listing 7.6 by replacing the do-while loop with a for loop.
    Rewrite the program in Listing 7.7. This time, use a while loop as the outer loop and a do-while loop as the inner loop. 

***

 

Related Items

মডুলার C প্রোগ্রামিং (Modular C Programming)

কেবল মাত্র একটি ফাংশন দিয়ে কোনো বড়ো জটিল সমস্যা সমাধানের চেষ্টা করা ভাল প্রোগ্রামিংয়ের পদ্ধতি নয়। সঠিক পদ্ধতি হ'ল সমস্যাটিকে কয়েকটি ছোট ছোট এবং সরল টুকরো করে ফেলা যাতে তা আরও বিশদে বোঝা যায় । তারপরে এই ছোট এবং সরল সমস্যাগুলি সমাধান করার জন্য ছোট ছোট ফাংশন ব্লক তৈরি করা এবং পরে সেগুলি নিয়মানুযায়ী সংযোজিত করা ।

Programming Style

Programming Style

In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q Is the C preprocessor part of the C compiler?

    A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.

Compiling Your Code Under Conditions

Compiling Your Code Under Conditions

You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.