Chapter 4 -
INTRODUCTION TO LOOPS
Questions:
1. Why do we use a loop in a C Program ?
সি প্রোগ্রামে আমরা লুপ ব্যবহার করি কেন?
Ans: In C programming, there are three loops: for loops, loop vial loop and vial. Loops in C can also be combined with other control statements such as brake statements, goto statements, and control statements.
(সি প্রোগ্রামিং-এ, তিনটি লুপ আছে: লুপ, while লুপের জন্য লুপ এবং while। সি-তে, লুপগুলিকে অন্যান্য নিয়ন্ত্রণ বিবৃতি যেমন ব্রেক বিবৃতি, পুরো বিবৃতি এবং নিয়ন্ত্রণ বিবৃতির সাথেও একত্রিত করা যেতে পারে।)
2. Do we need to use only one type of loop in a C program? Justify your answer by Writing a C Program.
(একটি সি প্রোগ্রামে কি আমাদের কেবল এক ধরণের লুপ ব্যবহার করতে হবে? একটি সি প্রোগ্রাম লিখে আপনার উত্তরের ন্যায্যতা যাচাই করুন।)
Ans: No, we can use all types of loops in a C program.
(না, আমরা একটি সি প্রোগ্রামে বিভিন্ন ধরণের লুপ ব্যবহার করতে পারি।)
3. What will happen if We Write a loop with 1 in place of the condition? try it in a Simple C Program. Hint:
(যদি আমরা কন্ডিশনটিকে লুপ দিয়ে ১ দিয়ে প্রতিস্থাপন করি? তাহলে কি হবে? একটি সাধারণ C প্রোগ্রামে এটি চেষ্টা করে দেখুন। ইঙ্গিত :)
while (1) (অন্যদিকে(1))
printf ("We must raise our voice against Corruption \n");
(প্রিন্টঅফ ("আমাদের দুর্নীতির বিরুদ্ধে কথা বলতে হবে")
Ans: Time (1) or (no non-zero value) is used for infinite loops. There are no conditions for some time. Since 1 or any non-zero has a value, the state is always true.
(অসীম লুপের জন্য সময় (1) অথবা (যেকোনো অ-শূন্য মান) ব্যবহার করা হয়। কিছু সময়ের জন্য কোন শর্ত নেই। যেহেতু 1 অথবা যেকোনো অ-শূন্য মান আছে, তাই অবস্থা সর্বদা সত্য।)
4. Name different portions of for a loop. Can we put more than one statement within a portion?
(লুপের বিভিন্ন অংশের নাম বল। আমরা কি একটি অংশের ভেতরে একাধিক স্টেটমেন্ট রাখতে পারি?)
Ans: There are two parts to one for the loop: a head that specifies repetition, and a body that is performed once per repetition. The header often declares a clear loop counter or loop variable, which allows the body to know which one is being iterated.
(একটি লুপের জন্য একটির দুটি অংশ থাকে: হেড যা পুনরাবৃত্তি সেট করে, এবং বডি যা প্রতি পুনরাবৃত্তিতে একবার এটি করে। হেডার প্রায়শই একটি স্পষ্ট লুপ কাউন্টার বা লুপ ভেরিয়েবল ঘোষণা করে, যা বডিকে জানতে দেয় কোনটি কাটা হচ্ছে।)
5. Answer with TRUE of FALSE.
মিথ্যার সত্যের জবাব দাও।
(i) If the condition of the while loop is false, the control comes to the second statement inside the loop.
(যদি লুপের সময় শর্তটি মিথ্যা হয়, তাহলে নিয়ন্ত্রণটি লুপের মধ্যে দ্বিতীয় বিবৃতিতে আসে।)
Ans: If the condition is false,
This means that the code should always be implemented first and then the expression or test status will be assessed. If this is true, the body of the code loop works again. ... If the expression is false, the loop is eliminated and controls the transition to the statement after the do-well loop.
(যদি শর্তটি মিথ্যা হয়,
এর মানে হল কোডটি সর্বদা প্রথমে কার্যকর করা উচিত এবং তারপরে এক্সপ্রেশন বা পরীক্ষার অবস্থা মূল্যায়ন করা হবে। যদি এটি সত্য হয়, তাহলে কোড লুপের মূল অংশটি আবার কাজ করবে। ... যদি এক্সপ্রেশনটি মিথ্যা হয়, তাহলে লুপটি সরানো হবে এবং ডু-ওয়েল লুপের পরে স্টেটমেন্টে রূপান্তর পরিচালনা করবে।)
(ii) We can use at most three loops in a single C program.
(একটি সি প্রোগ্রামে আমরা সর্বাধিক তিনটি লুপ ব্যবহার করতে পারি।)
Ans: False. We can use more than three loops in a C program
(মিথ্যা, আমরা একটি সি প্রোগ্রামে তিনটির বেশি লুপ ব্যবহার করতে পারি।)
(iii) The statements inside the do-while loop executes at least once even if the condition is false.
(ডু-ওয়েল লুপের মধ্যে থাকা স্টেটমেন্টগুলি কমপক্ষে একবার কার্যকর করা হয়, এমনকি যদি শর্তটি মিথ্যা হয়।)
Ans: The loop in the do-well loop is actually applied first then the situation is examined so that whether the result is applied in the first iteration is true or false, so we have concluded that the do-well loop is effective at least once despite the situation being incorrect.
(একটি ডু-ওয়েল লুপের লুপটি আসলে প্রথমে প্রয়োগ করা হয় তারপর পরিস্থিতি পরীক্ষা করা হয় যে ফলাফলটি প্রথম পুনরাবৃত্তিতে প্রয়োগ করা হয়েছে নাকি মিথ্যা, তাই আমরা এই সিদ্ধান্তে পৌঁছাই যে পরিস্থিতিটি ভুল হওয়া সত্ত্বেও ডু-ওয়েল লুপটি অন্তত একবার কার্যকর করা হয়েছে।)
(iv) Only the first statement inside the do-while loop executes when the condition is false.
(কন্ডিশনটি মিথ্যা হলে ডু-ওয়েল লুপের মধ্যে শুধুমাত্র প্রথম স্টেটমেন্টটি কার্যকর হয়।)
Ans: True.(সত্য)
(v) In a do-while loop, the condition is written at the end of the loop.
একটি ডু-ওয়েল লুপে, লুপের শেষে অবস্থা লেখা হয়।
Ans: False.(মিথ্যা)
6. Programming exercises:
A. Write a C program to find the summation of the following series
নিম্নলিখিত সিরিজের সারাংশ খুঁজে পেতে একটি C প্রোগ্রাম লিখুন।
(a). 12+22+32 + 42 + ... + N²
(b). 13+ 23 +33 +43 + ... + N³
(c). 12+23+ 34 + ... + N (N+1)
Ans:
B. Write a C program to continuously take a number as input and announce whether the number is odd or even. Hint: use do-while loop.
(একটি সংখ্যাকে ধারাবাহিক ইনপুট হিসেবে নেওয়ার জন্য একটি C প্রোগ্রাম লিখুন এবং সংখ্যাটিকে বিজোড় বা সমান ঘোষণা করুন। ইঙ্গিত: একটি ডু-ওয়াইল লুপ ব্যবহার করুন।)
Ans: in the while loop construct, first the condition is checked and then the statements are executed as long as the condition is true.
C. Write a C program to display the following pattern.
নিম্নলিখিত প্যাটার্নটি প্রদর্শনের জন্য একটি C প্রোগ্রাম লিখুন।
1
11
111
1111
11111
D. Write a C program to display the following pattern.
নিম্নলিখিত আৰ্হিটো প্ৰদৰ্শন কৰিবলৈ এটা চি প্ৰ'গ্ৰাম লিখক।
5
54
543
5432
54321
E. Write a C program to display the following pattern.
নিম্নলিখিত প্যাটার্নটি প্রদর্শনের জন্য একটি C প্রোগ্রাম লিখুন।
54321
5432
543
54
5