Problem 1: Finding summation of two numbers

সমস্যা 1: দুটা সংখ্যাৰ সংক্ষিপ্তবিৱৰণ বিচাৰি উলিওৱা

Let us start with a very simple program. Let us write a function to find the summation of two integers. Example 7.1 shows the code for this.

আহক আমি এটা অতি সৰল কাৰ্যসূচীৰে আৰম্ভ কৰোঁ আহক। দুটা পূৰ্ণসংখ্যাৰ সাৰাংশ বিচাৰি বলৈ আমি এটা ফাংচন লিখোঁ আহক। উদাহৰণ 7.1-এ ইয়াৰ বাবে কোড টো দেখুৱায়।

The main function first takes input in two integers a and b from the keyboard. Then it calls a function sum() for doing the calculation (line number 10). The control immediately goes to the definition of the function sum()..

মুখ্য ফাংচনটোৱে প্ৰথমে কীবৰ্ডৰ পৰা দুটা ইণ্টেগাৰ ক আৰু বি-ত ইনপুট লয়। তাৰ পিছত ই গণনা কৰাৰ বাবে ফাংচন যোগফল () বুলি কয় (শাৰী নম্বৰ 10)। নিয়ন্ত্ৰণ তৎক্ষণাৎ ফাংচন যোগফলৰ সংজ্ঞালৈ যায়।

In the definition of the function, we declare another integer “result” and the result is assigned the value of a+b. Finally, we return the value of result from the function that carries the summation of a and b (last line of function defition).

ফাংচনৰ সংজ্ঞাত, আমি আন এটা ইণ্টেগাৰ “ফলাফল” ঘোষণা কৰোঁ আৰু ফলাফলটোক এ+বি-ৰ মূল্য আৱণ্টন কৰা হয়। অৱশেষত, আমি ফলাফলৰ মূল্য ক আৰু খ(ফাংচন ডিফিয়েচনৰ অন্তিম শাৰী) বহন কৰা ফাংচনৰ পৰা ঘূৰাই দিওঁ।

As we return from the function, the control goes back to the place from where it made a call (line number 10). Then we display the value using a library function printf().

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

To check the program flow, we can write some additional printf() statements. Refer to the Example 7.2 that is the same program as Example 7.1 with some additional printf() statements.

প্ৰ’গ্ৰামৰ প্ৰবাহ পৰীক্ষা কৰিবলৈ, আমি কিছুমান অতিৰিক্ত প্ৰিণ্টফ() বিবৃতি লিখিব পাৰোঁ। উদাহৰণ 7.2 চাওক যি হৈছে কিছুমান অতিৰিক্ত প্ৰিণ্টফ() বিবৃতিৰ সৈতে উদাহৰণ 7.1-ৰ দৰে একে প্ৰ’গ্ৰাম।

Example 7.2 A C program using a function extra printf()

As we execute the above program, we see the program control printf() are displayed the following output. We understand from the output that as we call a function, the control goes to the definition of it and then it comes to the caller.

আমি ওপৰোক্ত প্ৰ’গ্ৰামটো সম্পাদন কৰাৰ লগে লগে, আমি প্ৰ’গ্ৰাম নিয়ন্ত্ৰণ প্ৰিণ্টফ() নিম্নলিখিত আউটপুটপ্ৰদৰ্শন কৰা দেখিছোঁ। আমি আউটপুটৰ পৰা বুজি পাওঁ যে আমি ফাংচন এটা কওঁ, নিয়ন্ত্ৰণটো ইয়াৰ সংজ্ঞালৈ যায় আৰু তাৰ পিছত ই কলাৰৰ ওচৰলৈ আহে।