সি প্রোগ্রামিং ভাষায় স্ট্রাকচার ব্যবহার করে সার্কেলের এরিয়া, সিলিন্ডারের এরিয়া এবং ভলিউম বের করা যায়।
- সার্কেলের এরিয়া বের করার লজিক:
s.areacircle = (float)pi*s.radius*s.radius;
- সিলিন্ডারের এরিয়া বের করার লজিক:
s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle;
- সিলিন্ডারের ভলিউম বের করার লজিক:
s.volumecylinder = s.areacircle*s.line;
অ্যালগরিদম
স্ট্রাকচার ব্যবহার করে সার্কেল এবং সিলিন্ডারের এরিয়া ও ভলিউম বের করার অ্যালগরিদম:
Step 1 − স্ট্রাকচার মেম্বার ডিক্লেয়ার করুন।
Step 2 − ইনপুট ভেরিয়েবল ডিক্লেয়ার ও ইনিশিয়ালাইজ করুন।
Step 3 − সিলিন্ডারের লেন্থ এবং রেডিয়াস ইনপুট নিন।
Step 4 − সার্কেলের এরিয়া কম্পিউট করুন।
Step 5 − সিলিন্ডারের এরিয়া কম্পিউট করুন।
Step 6 − সিলিন্ডারের ভলিউম কম্পিউট করুন।
উদাহরণ
স্ট্রাকচার ব্যবহার করে সার্কেল এবং সিলিন্ডারের এরিয়া ও ভলিউম বের করার সি প্রোগ্রাম:
#include<stdio.h> struct shape{ float line; float radius; float areacircle; float areacylinder; float volumecylinder; }; int main(){ struct shape s; float pi = 3.14; //taking the input from user printf("Enter a length of line or height : "); scanf("%f",&s.line); printf("Enter a length of radius : "); scanf("%f",&s.radius); //area of circle s.areacircle = (float)pi*s.radius*s.radius; printf("Area of circular cross-section of cylinder : %.2f\n",s.areacircle); //area of cylinder s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle; printf("Surface area of cylinder : %.2f\n", s.areacylinder); //volume of cylinder s.volumecylinder = s.areacircle*s.line; printf("volume of cylinder : %.2f\n", s.volumecylinder); return 0; }
আউটপুট
Enter a length of line or height: 34 Enter a length of radius: 2 Area of circular cross-section of cylinder: 12.56 Surface area of cylinder: 452.16 volume of cylinder : 427.04