|
230 | 230 | // Topic : C Programming - Functions
|
231 | 231 | // Level 2 – Intermediate Function Problems
|
232 | 232 | // ============================================================
|
| 233 | + |
| 234 | +// --------------------------------------------------------------------------------- |
| 235 | + |
| 236 | + |
233 | 237 |
|
234 | 238 | // // ============================================================
|
235 | 239 | // 📌 Factorial Finder
|
236 | 240 | // 👉👉 🔹 Q- 7: একটি ফাংশন লিখো যা একটি সংখ্যা ইনপুট নিয়ে তার Factorial বের করবে।
|
237 | 241 | // ============================================================
|
238 | 242 |
|
| 243 | +// #include <stdio.h> |
| 244 | +// int factorial(int n); |
| 245 | +// int main(){ |
| 246 | +// int n ; |
| 247 | +// printf("Enter Number ") ; |
| 248 | +// scanf("%d" , &n); |
| 249 | +// int fac = factorial(n); |
| 250 | +// printf("factorial is %d\n" , fac); |
239 | 251 |
|
| 252 | +// return 0; |
| 253 | +// } |
240 | 254 |
|
| 255 | +// int factorial(int n){ |
| 256 | +// int result = 1 ; |
| 257 | +// for (int i = 1 ; i<=n ; i++){ |
| 258 | +// result = i*i; |
| 259 | +// } |
| 260 | +// return result ; |
| 261 | + |
| 262 | +// } |
| 263 | + |
| 264 | +// // ============================================================ |
| 265 | +// 📌 Factorial Finder |
| 266 | +// 👉👉 🔹 Q- 7: একটি ফাংশন লিখো যা একটি সংখ্যা ইনপুট নিয়ে তার Factorial বের করবে। |
| 267 | +// 👉 🔹 Review Write code |
| 268 | +// ============================================================ |
241 | 269 |
|
242 | 270 | #include <stdio.h>
|
243 |
| -int factorial(int n); |
| 271 | +int factorial(int a) ; |
244 | 272 | int main(){
|
245 |
| - int n ; |
246 |
| - printf("Enter Number ") ; |
247 |
| - scanf("%d" , &n); |
248 |
| - int fac = factorial(n); |
249 |
| - printf("factorial is %d\n" , fac); |
250 |
| - |
| 273 | + int a ; |
| 274 | + printf("Enter Number :"); |
| 275 | + scanf("%d",&a); |
| 276 | + int fact = factorial(a); |
| 277 | + printf("Factorial is %d\n" , fact); |
251 | 278 | return 0;
|
252 | 279 | }
|
253 | 280 |
|
254 |
| -int factorial(int n){ |
255 |
| - int result = 1 ; |
256 |
| - for (int i = 1 ; i<=n ; i++){ |
257 |
| - result = i*i; |
258 |
| - } |
259 |
| - return result ; |
| 281 | +int factorial(int a ){ |
| 282 | + int result = 1; |
| 283 | + for(int i = 1; i<=a; i++){ |
| 284 | + result = i*i; |
| 285 | + } |
260 | 286 |
|
| 287 | + return result; |
261 | 288 | }
|
262 | 289 |
|
263 | 290 |
|
|
0 commit comments