Chapter 6 -
ARRAYS IN C
Exercise
1. Define array. Why do we use arrays in computer programs?
(অ্যারে নির্ধারণ করুন। কেন আমরা কম্পিউটার প্রোগ্রামে অ্যারে ব্যবহার করি?)
Ans: We use arrays in computer programs because-In coding and programming, arrays are a collection of items, or data, stored in adjacent memory locations, also known as database systems. The purpose of an array is to store multiple pieces of data of the same type together.
2. Can we store both integer and float types of data in a single array? Demonstrate this by writing a simple C program.
(আমরা কি একটি অ্যারেতে পূর্ণসংখ্যা এবং ফ্লোট উভয় ধরণের ডেটা সংরক্ষণ করতে পারি? একটি সাধারণ সি প্রোগ্রাম লিখে এটি প্রদর্শন করুন।)
Ans: We cannot store data in both integers and float types.
In the above program, when array elements are taken as integers, the program prints the correct output. But if we take the input as a float value (e.g. 3.14,2.54,5.7,........) an error will occur.
3. Write the indices of the first and last element of the following array declaration. char city [7]=('S', T, 'L', 'C', 'H', 'A', 'R', };
(নিম্নলিখিত এৰে ঘোষণাৰ প্ৰথম আৰু অন্তিম উপাদানৰ সূচকবোৰ লিখক। চাৰ চিটি [7]=('এছ', টি,'এল', 'চি', 'চি', 'এইচ', 'এ', 'আৰ', };)
Ans: Indices of the first element of the array is 0. and Indices of the last element of the array is 6.
(অ্যারে ঘোষণার প্রথম উপাদানের সূচক হল 0। এবং অ্যারে ঘোষণার শেষ উপাদানের সূচক হল 6।)
4. Write a C program and declare an integer type array with capacity 7. Take input to the array from the keyboard. Display the 8th element of the array. Hint: display num[7] if num is the name of the array. Analyze the output.
(একটি C প্রোগ্রাম লিখুন এবং 7 পাওয়ার সহ একটি পূর্ণসংখ্যা ধরণের অ্যারে ঘোষণা করুন। কীবোর্ড থেকে অ্যারেতে ইনপুট নিন। অ্যারের 8 তম উপাদানটি প্রদর্শন করুন। ইঙ্গিত: সংখ্যাটি প্রদর্শন করুন [7] যদি সংখ্যাটি অ্যারের নাম হয়। আউটপুট পার্স করুন।)।
Ans:
5. Write a C program and declare an integer type array with 7 elements in it. Display the address of the individual elements in the array.
(একটি C প্রোগ্রাম লিখুন এবং ৭টি উপাদান সহ একটি পূর্ণসংখ্যা ধরণের অ্যারে ঘোষণা করুন। অ্যারেতে ক্লাস্টার করা উপাদানগুলির ঠিকানাগুলি প্রদর্শন করুন।)
Ans: To create an array, define the type of data (for example int) and specify the name of the array after the class brackets []. To include values here, use a less-varying list within curly braces: in my number[] = {25, 50, 75, 100};
(একটি অ্যারে তৈরি করতে, ডেটা টাইপ (যেমন int) উল্লেখ করুন এবং অ্যারের নাম উল্লেখ করুন এবং তারপরে ক্লাস ব্র্যাকেট [] দিন। এখানে মান অন্তর্ভুক্ত করতে, কোঁকড়া বন্ধনীর ভিতরে একটি কম-পরিবর্তনীয় তালিকা ব্যবহার করুন: int my number[] = {25, 50, 75, 100};)
6. Write a C program and declare two integer type arrays, each with capacity 7. Take input only to the first array. Write a loop to copy the elements of the first array to the second one. Display the elements of the second array.
(একটি C প্রোগ্রাম লিখুন এবং দুটি পূর্ণসংখ্যা ধরণের অ্যারে ঘোষণা করুন, প্রতিটির পাওয়ার 7। শুধুমাত্র প্রথম অ্যারেতে ইনপুট সরান। প্রথম অ্যারের উপাদানগুলিকে দ্বিতীয়টিতে প্রতিলিপি করার জন্য একটি লুপ লিখুন। দ্বিতীয় অ্যারের উপাদানগুলি প্রদর্শন করুন।)
Ans:
7. Write a strategy to find the summation of all the even numbers stored in an array. Write a C program for the same. If the array elements are (1, 2, 4, 3, 5, 6, 7, 7, 8), the output of the program will be 20.
একটি অ্যারেতে সঞ্চিত সকল সমান সংখ্যার যোগফল বের করার একটি কৌশল লিখ। এর জন্য একটি সি প্রোগ্রাম লিখ। যদি অ্যারের উপাদানগুলি (1, 2, 4, 3, 5, 6, 7, 7, 8) হয়, তাহলে প্রোগ্রামের আউটপুট হবে
Ans:
8. Write a strategy to find the summation of all the even positioned numbers stored in an array. Write a C program for the same. If the array elements are {1, 2, 4, 3, 5, 6, 7, 7, 8), the output of the program will be 18.
একটি অ্যারেতে সংরক্ষিত সকল সমান অবস্থানে থাকা সংখ্যার সারাংশ খুঁজে বের করার একটি কৌশল লিখ। এর জন্য একটি সি প্রোগ্রাম লিখ। যদি অ্যারের উপাদানগুলি {1, 2, 4, 3, 5, 6, 7, 7, 8 হয়, তাহলে প্রোগ্রামটির আউটপুট 18 হবে।
Ans:
9. Write the logic to replace only the first occurrence of an element in an array. For example, if the array elements are {1, 2, 3, 4, 5, 1, 2, 3] and we want to replace element 3 by 0, the array content becomes {1, 2, 0, 4, 5, 1, 2, 3). Write a complete C program incorporating the logic.
একটি অ্যারেতে শুধুমাত্র প্রথমবারের মতো একটি উপাদানের উপস্থিতি পরিবর্তন করার জন্য যুক্তি লিখুন। উদাহরণস্বরূপ, যদি অ্যারের উপাদানগুলি {1, 2, 3, 4, 5, 1, 2, 3] হয় এবং আমরা 3 উপাদানকে 0 দিয়ে প্রতিস্থাপন করতে চাই, তাহলে অ্যারের বিষয়বস্তু হবে {1, 2, 0, 4, 5, 1, 2, 3)। আর্গুমেন্ট সহ একটি সম্পূর্ণ সি প্রোগ্রাম লিখুন।
Ans:
10. Write the logic to replace only the last occurrence of an element in an array. For example, if the array elements are (1, 2, 3, 4, 5, 1, 2, 3) and we want to replace element 3 by 0, the array content becomes (1, 2, 3, 4, 5, 1, 2, 0). Write a complete C program incorporating the logic.
Ans:
11. Write a C program to replace all the even positioned elements in an integer array by 0. For example, if the array elements are {1, 2, 3, 9, 5, 5, 7, 1, 9), it becomes (1, 0, 3, 0, 5, 0, 7, 0, 9).
পূর্ণসংখ্যা অ্যারের সকল সমান অবস্থানে থাকা উপাদানকে 0 দ্বারা প্রতিস্থাপন করার জন্য একটি C প্রোগ্রাম লিখুন। উদাহরণস্বরূপ, যদি অ্যারের উপাদানগুলি {1, 2, 3, 9, 5, 5, 7, 1, 9 হয়, তাহলে এটি (1, 0, 3, 0, 5, 0, 7, 0, 9) হয়ে যায়।
Ans:
12. Write a strategy to replace all the odd numbers in an integer array by 0. For example, if the array elements are (1, 2, 3, 9, 5, 5, 7, 1, 9), it becomes (0, 2, 0, 0, 0, 0, 0, 0, 0). Write a C program for the same.
একটি পূর্ণসংখ্যা অ্যারেতে সমস্ত বিজোড় সংখ্যাকে 0 দিয়ে প্রতিস্থাপন করার একটি কৌশল লিখ। উদাহরণস্বরূপ, যদি অ্যারের উপাদানগুলি (1, 2, 3, 9, 5, 5, 7, 1, 9) হয়, তাহলে এটি (0, 2, 0, 0, 0, 0, 0, 0, 0, 0) হবে। এর জন্য একটি সি প্রোগ্রাম লিখ।
13. Write a C program to store your name and your mother's name in two different strings. Display them one after another.
তোমার নাম এবং তোমার মায়ের নাম দুটি আলাদা স্ট্রিংয়ে সংরক্ষণ করার জন্য একটি C প্রোগ্রাম লিখ। একের পর এক এগুলো দেখাও।
Ans:
14. Write a C program to declare 3 integer type arrays to store the marks of 10 students scored in 3 different subjects. Take another integer to store the average marks of the students. The average mark of a student is the average of the marks scored by the student in 3 subjects. This should be calculated and inserted by the program. Then you should display the average marks of the students. The program should also display "PASS" or "FAIL" along with the average as per the rule: PASS if average >= 45, FAIL otherwise.
৩টি পৃথক বিষয়ে নম্বর পাওয়া ১০ জন শিক্ষার্থীর নম্বর সংরক্ষণের জন্য ৩টি পূর্ণসংখ্যার একটি অ্যারে ঘোষণা করার জন্য একটি C প্রোগ্রাম লিখ। শিক্ষার্থীদের গড় নম্বর সংরক্ষণের জন্য আরেকটি পূর্ণসংখ্যা নিন। একজন শিক্ষার্থীর গড় নম্বর হলো ৩টি বিষয়ে শিক্ষার্থীর প্রাপ্ত নম্বরের গড়। এটি গণনা করা উচিত এবং প্রোগ্রাম দ্বারা অন্তর্ভুক্ত করা উচিত। তাহলে আপনার শিক্ষার্থীদের গড় নম্বর প্রদর্শন করা উচিত। প্রোগ্রামটিতে নিয়ম অনুসারে গড়ের সাথে "পাস" অথবা "ফেল" প্রদর্শন করা উচিত: গড় হলে পাস >= ৪৫, অন্যথায় ফেল।
Ans:
15. Write any two limitations of arrays. Can you store your name and roll number in the same aray?
অ্যারের যেকোনো দুটি সীমাবদ্ধতা লিখ। তুমি কি তোমার নাম এবং রোল নম্বর একই অ্যারেতে সংরক্ষণ করতে পারো?
Ans: