Scenario-Based Questions in C

 Exploring C Programming Through Scenario-Based Questions 🤔💻

Hello fellow programmers! Today, let's delve into the world of C programming by tackling 15 scenario-based questions. 🚀

1. Scenario: Swap Values Without a Third Variable

Question: Can you swap the values of two variables without using a third variable?

c
#include <stdio.h> int main() { int a = 5, b = 10; printf("Before swap: a = %d, b = %d\n", a, b); a = a + b; b = a - b; a = a - b; printf("After swap: a = %d, b = %d\n", a, b); return 0; }

2. Scenario: Detect Leap Year

Question: Can you determine if a given year is a leap year?

c
#include <stdio.h> 
int main()
int year; 
// Your code here
return 0; }

3. Scenario: Array Manipulation

Question: How can you find the sum and average of elements in an array?

c
#include <stdio.h> 
int main() {
int numbers[] = {10, 20, 30, 40, 50}; 
// Your code here 
return 0
}

4. Scenario: Factorial Calculation

Question: Compute the factorial of a given number.

c
#include <stdio.h> 
int main()
int n; 
// Your code here
return 0; }

5. Scenario: Palindrome Checker

Question: Determine if a given word is a palindrome.

c
#include <stdio.h>
#include <string.h> 
int main()
char word[50]; 
// Your code here 
return 0
}

6. Scenario: File Handling

Question: How do you read from and write to a file in C?

c
#include <stdio.h> 
int main() {
// Your code here 
return 0
}

7. Scenario: Dynamic Memory Allocation

Question: Allocate memory for an array dynamically.

c
#include <stdio.h> 
int main()
{
int n; // Your code here 
return 0
}

8. Scenario: Structures and Functions

Question: Create a structure to represent a student and write a function to display student details.

c
#include <stdio.h> 
struct Student 
{ 
char name[50];
int age;
float marks;
 }; // Your code here 
int main()
{ // Your code here 

return 0
}

9. Scenario: Linked List Basics

Question: Implement a simple linked list.

c
#include <stdio.h>
struct Node { 
int data; 
struct Node* next;
};
// Your code here int main() 
// Your code here return 0
}

10. Scenario: Recursion Exploration

Question: Solve a problem using recursion. (e.g., Fibonacci sequence)

c
#include <stdio.h> 
// Your code here 
int main()
{ // Your code here
return 0
}

Feel free to tackle these scenarios, explore, and enjoy the process of learning C programming! Remember, each question is an opportunity to sharpen your coding skills. Happy coding! 🌟💻 #CProgramming #ScenarioBasedLearning #CodingFun