প্রোগ্রামিংয়ের মৌলিক ধারণা/সি++ লুপ উদাহরণ
অবয়ব
গণণা
[সম্পাদনা]// এই প্রোগ্রামটি ব্যবহারকারী-নির্ধারিত স্টার্ট, স্টপ এবং ইনক্রিমেন্ট মান ব্যবহার করে While, Do এবং For লুপ গণনা প্রদর্শন করে ।
//
// তথ্যসূত্র:
// https://en.wikibooks.org/wiki/C%2B%2B_Programming
#include <iostream>
using namespace std;
int getValue(string name);
void whileLoop(int start, int stop, int increment);
void doLoop(int start, int stop, int increment);
void forLoop(int start, int stop, int increment);
int main() {
int start = getValue("শুরুর");
int stop = getValue("শেষের");
int increment = getValue("বৃদ্ধির");
whileLoop(start, stop, increment);
doLoop(start, stop, increment);
forLoop(start, stop, increment);
return 0;
}
int getValue(string name) {
int value;
cout << name << " মান লিখুন:" << endl;
cin >> value;
return value;
}
void whileLoop(int start, int stop, int increment) {
cout << "While লুপ গণনা করছে " << start << " থেকে " <<
stop << " পর্যন্ত, প্রতি ধাপে " << increment << " করে:" << endl;
int count = start;
while (count <= stop) {
cout << count << endl;
count = count + increment;
}
}
void doLoop(int start, int stop, int increment) {
cout << "Do-while লুপ গণনা করছে " << start << " থেকে " <<
stop << " পর্যন্ত, প্রতি ধাপে " << increment << " করে:" << endl;
int count = start;
do {
cout << count << endl;
count = count + increment;
} while (count <= stop);
}
void forLoop(int start, int stop, int increment) {
cout << "For লুপ গণনা করছে " << start << " থেকে " <<
stop << " পর্যন্ত, প্রতি ধাপে " << increment << " করে:" << endl;
for (int count = start; count <= stop; count += increment) {
cout << count << endl;
}
}
আউটপুট
[সম্পাদনা]শুরুর মান লিখুন: 1 শেষের মান লিখুন: 5 বৃদ্ধির মান লিখুন: 1 While লুপ গণনা করছে 1 থেকে 5 পর্যন্ত, প্রতি ধাপে 1 করে: 1 2 3 4 5 Do-while লুপ গণনা করছে 1 থেকে 5 পর্যন্ত, প্রতি ধাপে 1 করে: 1 2 3 4 5 For লুপ গণনা করছে 1 থেকে 5 পর্যন্ত, প্রতি ধাপে 1 করে: 1 2 3 4 5