Chapter 7 -

FUNCTIONS IN C 

Exercise

1. What is a global variable in C? Why do we need such a variable?

(C তে একটি গ্লোবাল ভ্যারিয়েবল কী? আমাদের কেন এমন ভ্যারিয়েবলের প্রয়োজন?)

Ans: A variable defined outside the range of all functions is known as a global variable in C. Global variables have a global range, so these variables can be input and modified by any function, structure, or any category C.

Variables are used to store references and information manipulated in a computer program. It also provides a way to label data with descriptive names so that our programs are readers and we can understand more clearly.

(সকল ফাংশনের আওতার বাইরে সংজ্ঞায়িত একটি চলককে C তে গ্লোবাল ভেরিয়েবল বলা হয়। গ্লোবাল ভেরিয়েবলের একটি গ্লোবাল স্কোপ থাকে, তাই এই চলকগুলিকে যেকোনো ফাংশন, কাঠামো বা যেকোনো শ্রেণী C দ্বারা ইনপুট এবং পরিবর্তন করা যেতে পারে)।

একটি কম্পিউটার প্রোগ্রামে প্রসঙ্গ এবং ডেটা সংরক্ষণের জন্য ভেরিয়েবল ব্যবহার করা হয়। এটি বর্ণনামূলক নাম দিয়ে ডেটা লেবেল করার একটি উপায়ও প্রদান করে যাতে আমাদের প্রোগ্রামগুলি পঠনযোগ্য হয় এবং আমরা সেগুলি আরও স্পষ্টভাবে বুঝতে পারি।)

2. Write the syntax of a function declaration. The name of the function is calculateAge (). The function accepts the current year and birth year of a person. The function returns the age of the person.

(একটি ফাংশন ডিক্লারেশনের সিনট্যাক্স লিখুন। ফাংশনের নাম হল calculate()। ফাংশনটি একজন ব্যক্তির বর্তমান বছর এবং জন্মের বছর গ্রহণ করে। ফাংশনটি ব্যক্তির বয়স ফেরত দেয়।)

Ans: A feature announcement tells the compiler about the function name and how to switch the function. The actual body of functions can be defined separately. maximum (Int., Inc.); A feature declaration is required when defining the function in one source file and when calling the function to another file.

Take the difference between the current year and the year of their birth: year = present year - year of birth.

Take the difference between the present month and the month of their birth: month = current month - month of birth.

The next dated function calculates a person's age.

(একটি বৈশিষ্ট্য ঘোষণা কম্পাইলারকে ফাংশনের নাম এবং ফাংশনটি কীভাবে পরিবর্তন করতে হয় তা বলে। ফাংশনের আসল অংশ আলাদাভাবে সংজ্ঞায়িত করা যেতে পারে। সর্বোচ্চ (int,inc.); একটি উৎস ফাইলে ফাংশনটি নির্দিষ্ট করার সময় এবং অন্য ফাইলে ফাংশনটি কল করার সময় একটি বৈশিষ্ট্য ঘোষণা প্রয়োজন।)

বর্তমান বছর এবং তাদের জন্ম বছরের মধ্যে পার্থক্য নিন: বছর = বর্তমান বছর - জন্ম বছর।

বর্তমান মাস এবং তাদের জন্ম মাসের মধ্যে পার্থক্য নিন: মাস = বর্তমান মাস - জন্মের মাস।

পরবর্তী তারিখ ফাংশনটি একজন ব্যক্তির বয়স গণনা করে।)

3. Write the code segment for the function definition of the above function calculateAge.

(উপরের ফাংশন গণনার ফাংশন সংজ্ঞার কোডটি উদ্ধৃত করুন।)

Ans: Act with logic and returned values. This function has arguments and returns a value: ...

Works with logic and without return value. ...

Act without logic and with returned values. ...

Act without logic and without returned values.

Most usage guides will say that you want to talk about two people or things ('sitting between John and Carol') and more than two people or things ('students are talking among themselves').

(আর্গুমেন্ট এবং রিটার্ন মান নিয়ে কাজ করুন। এই ফাংশনে আর্গুমেন্ট আছে এবং একটি মান রিটার্ন করে: ...

আর্গুমেন্টের সাথে এবং রিটার্ন মান ছাড়াই কাজ করে। ...

আর্গুমেন্ট ছাড়া এবং রিটার্ন করা মান নিয়ে কাজ করুন। ...

যুক্তি অবিহনে আৰু ঘূৰাই দিয়া মূল্যঅবিহনে কাম কৰক।

বেশিরভাগ ব্যবহার নির্দেশিকা বলবে যে আপনি দুজন ব্যক্তি বা জিনিস ('জন এবং ক্যারলের মধ্যে বসে') এবং দুজনের বেশি ব্যক্তি বা জিনিস ('শিক্ষার্থীরা নিজেদের সাথে কথা বলছে') সম্পর্কে কথা বলতে চান।

4. What are different types of functions in C ? Differentiate among them.

(C তে বিভিন্ন ধরণের ফাংশন কী কী? তাদের মধ্যে পার্থক্য করুন।)

5. Differentiate between caller and callee functions, write a small C progarm and identify. the caller and callee function in it.

(কলার এবং ক্যালি ফাংশনের মধ্যে পার্থক্য করুন, একটি ছোট সি প্রোগ্রাম লিখুন এবং সনাক্ত করুন। কলিং এবং কলিং এখানে কাজ করে।)

Ans:  

6. When do we call a function user-defined? Is printf() a user-defined function? Justify.

(আমরা কখন একটি ফাংশনকে user-defined বলি? printof() কি একটি user-defined ফাংশন? ঠিক আছে।)

Ans: 

7. Can we have two functions with the same name but with different numbers of parameters in a single C program? Write a simple C program to justify your answer.

(একটি সি প্রোগ্রামে কি আমরা একই নামে কিন্তু ভিন্ন সংখ্যক প্যারামিটার সহ দুটি ফাংশন করতে পারি? আপনার উত্তরের ন্যায্যতা প্রমাণ করার জন্য একটি সহজ সি প্রোগ্রাম লিখুন।)

Ans: 

8. What are different components of a function? Show with a complete C program.

(একটি ফাংশনের বিভিন্ন উপাদান কী কী? একটি সম্পূর্ণ C প্রোগ্রাম দিয়ে দেখান।)

Ans:  

9. Define recursive function. Can we use a recursive function to solve all kinds of problems?

(পুনরাবৃত্ত ফাংশন সেট করুন। আমরা কি সকল ধরণের সমস্যা সমাধানের জন্য একটি পুনরাবৃত্ত ফাংশন ব্যবহার করতে পারি?)

Ans: 

10. Consider the below code and list all the syntax errors.

(নীচের কোডটি বিবেচনা করুন এবং সমস্ত বাক্য গঠন ত্রুটি তালিকাভুক্ত করুন।)

Ans: 









11. Consider the code segment below and find out the output if the user enters 5 from the keyboard when asked for.

(নীচের কোডের অংশটি বিবেচনা করুন এবং ব্যবহারকারী যদি প্রয়োজনে কীবোর্ড থেকে 5 প্রবেশ করে তবে আউটপুটটি খুঁজুন।)

Ans:  




 12. Write a C program and define a function square() that accepts a number as the parameter and returns the square of that number as output.

(একটি C প্রোগ্রাম লিখুন এবং একটি ফাংশন square() সংজ্ঞায়িত করুন যা একটি সংখ্যাকে প্যারামিটার হিসেবে গ্রহণ করে এবং সেই সংখ্যার বর্গকে আউটপুট হিসেবে প্রদান করে।)

Ans: 

13. Write a C program and define a function search () that searches an element in an array and returns the index of the element.

(একটি সি প্রোগ্রাম লিখুন এবং একটি ফাংশন অনুসন্ধান () সংজ্ঞায়িত করুন যা একটি অ্যারেতে একটি উপাদান অনুসন্ধান করে এবং উপাদানটির সূচক প্রদান করে।)

Ans:

14. Write a C program and define a recursive function to find the summation of first N natural numbers.

(একটি C প্রোগ্রাম লিখুন এবং প্রথম N প্রাকৃতিক সংখ্যার সংক্ষিপ্ত রূপ খুঁজে বের করার জন্য একটি পুনরাবৃত্ত ফাংশন নির্ধারণ করুন।)

Ans: 

15. Write a C program and define a function add() that accepts three integers. These integers indicate indices of an integer array. The function returns the summation of the elements stored in those indices.

(একটি C প্রোগ্রাম লিখুন এবং তিনটি পূর্ণসংখ্যা গ্রহণকারী add() ফাংশনটি সংজ্ঞায়িত করুন। এই পূর্ণসংখ্যাগুলি একটি পূর্ণসংখ্যা অ্যারের সূচকগুলিকে নির্দেশ করে। ফাংশনটি সেই সূচকগুলিতে সংরক্ষিত উপাদানগুলির একটি সারাংশ প্রদান করে।)





For example, if we call the function add( 0, 2, 5), the function will return 24. The output is formed by 7+ 8+ 9 because elements at indices 0, 2 and 5 are 7, 8 and 9 respectively.

(উদাহরণস্বরূপ, যদি আমরা ফাংশনটিকে Add(0, 2, 5) বলি, তাহলে ফাংশনটি 24 রিটার্ন করবে। আউটপুট 7+ 8+ 9 দ্বারা গঠিত হয় কারণ 0, 2 এবং 5 সূচকের উপাদানগুলি যথাক্রমে 7, 8 এবং 9।)

Ans: