6.5.6.Displaying the array elements in reverse order

6.5.6. বিপৰীত ক্ৰমত এৰে উপাদানবোৰ প্ৰদৰ্শন কৰা

In all the programs above, we have traversed the array elements from lower index to higher index (from 0 to SIZE-1). In this problem, we are asked to display the elements in reverse order.

ওপৰৰ সকলো প্ৰ’গ্ৰামত, আমি এৰে উপাদানবোৰ নিম্ন সূচকৰ পৰা উচ্চতৰ সূচকলৈ (0 ৰ পৰা আকাৰ-1লৈ) অতিক্ৰম কৰিছো। এই সমস্যাটোত, আমাক উপাদানবোৰ বিপৰীত ক্ৰমত প্ৰদৰ্শন কৰিবলৈ কোৱা হয়।

If above is the array, the program should display IT A HAWUG.

যদি ওপৰত এৰে থাকে, প্ৰ’গ্ৰামটোৱে আইটি এ এইচএডব্লিউইউজি প্ৰদৰ্শন কৰিব লাগে।

To do so, we can start with the highest index and we can move toward the lower index by decrementing the index value. We continue to display one element at a time using a printf() statement. We can do this in each iteration of a loop.

এনে কৰিবলৈ, আমি সৰ্বোচ্চ সূচকৰ সৈতে আৰম্ভ কৰিব পাৰোঁ আৰু আমি সূচীৰ মূল্য হ্ৰাস কৰি নিম্ন সূচকৰ ফালে আগবাঢ়িব পাৰোঁ। আমি প্ৰিণ্টফ() বিবৃতি এটা ব্যৱহাৰ কৰি এবাৰত এটা উপাদান প্ৰদৰ্শন কৰা অব্যাহত ৰাখিছোঁ। আমি এইটো এটা লুপৰ প্ৰতিটো পুনৰাবৃত্তিত কৰিব পাৰোঁ।

The following code segment can do this.

নিম্নলিখিত কোড খণ্ডটোৱে এইটো কৰিব পাৰে।

Here, char array is the name of a character type array which has SIZE number of elements in it. The indices of the array elements start at 0 and end at SIZE-1. As we are dealing with a character type array, we used %c in the printf() statement to display the elements.

ইয়াত, char array হৈছে এটা বৰ্ণ প্ৰকাৰ এৰেৰ নাম য’ত আকাৰৰ উপাদানৰ সংখ্যা আছে। এৰে উপাদানবোৰৰ সূচকবোৰ 0-ত আৰম্ভ হয় আৰু আকাৰ-1-ত শেষ হয়। যিহেতু আমি এটা বৰ্ণপ্ৰকাৰ এৰেৰ সৈতে লেনদেন কৰি আছোঁ, আমি উপাদানবোৰ প্ৰদৰ্শন কৰিবলৈ প্ৰিণ্টফ() বিবৃতিত %চি ব্যৱহাৰ কৰিছিলো।

A complete C program demonstrating the same is presented in Example 6.9. In the program, the variable index is initialized with 7 because we have eight elements in the array and 7 is the index of the last element.

ইয়াক প্ৰদৰ্শন কৰা এটা সম্পূৰ্ণ চি প্ৰ’গ্ৰাম উদাহৰণ 6.9-ত উপস্থাপন কৰা হৈছে। প্ৰ’গ্ৰামটোত, পৰিৱৰ্তনশীল সূচক7 ৰ সৈতে আৰম্ভ কৰা হয় কিয়নো আমাৰ এৰেত আঠটা উপাদান আছে আৰু 7 হৈছে অন্তিম উপাদানৰ সূচী।