Skip to main content

Posts

Showing posts with the label c

๐Ÿงช Practice Problems Answer Day 2 DSA with C

  ✅ 1. Find Maximum and Minimum in an Array # include <stdio.h> int main () { int n, i; int arr[ 100 ], max, min; printf ( "Enter number of elements: " ); scanf ( "%d" , &n); printf ( "Enter %d elements:\n" , n); for (i = 0 ; i < n; i++) { scanf ( "%d" , &arr[i]); } max = min = arr[ 0 ]; for (i = 1 ; i < n; i++) { if (arr[i] > max) max = arr[i]; if (arr[i] < min) min = arr[i]; } printf ( "Maximum: %d\n" , max); printf ( "Minimum: %d\n" , min); return 0 ; } ✅ 2. Count Occurrences of a Given Number # include <stdio.h> int main () { int n, x, count = 0 ; int arr[ 100 ]; printf ( "Enter number of elements: " ); scanf ( "%d" , &n); printf ( "Enter %d elements:\n" , n); for ( int i = 0 ; i < n; i++) { ...

๐Ÿš€ DSA with C – Day 2: Arrays & Linear Search

  ๐ŸŽฏ Goal: Understand arrays in C. Learn how to use loops with arrays . Implement Linear Search algorithm. Practice multiple array-based programs. ๐Ÿง  Theory: What is an Array? An array is a collection of elements stored in contiguous memory . All elements must be of the same type . Indexing starts from 0 in C. ๐Ÿ”ง Declaration and Initialization int arr[ 5 ]; // Declaration int arr[ 5 ] = { 1 , 2 , 3 , 4 , 5 }; // Initialization ๐Ÿ‘จ‍๐Ÿ’ป Basic Program: Input & Output in Arrays # include <stdio.h> int main () { int arr[ 5 ]; printf ( "Enter 5 numbers:\n" ); for ( int i = 0 ; i < 5 ; i++) { scanf ( "%d" , &arr[i]); } printf ( "You entered:\n" ); for ( int i = 0 ; i < 5 ; i++) { printf ( "%d " , arr[i]); } return 0 ; } ๐Ÿ” Linear Search in C ➕ Problem: Given an array and a number x , find if x exists in the array. ✅ Code...

๐Ÿš€ DSA with C – Day 1: Introduction & Setup

  ๐Ÿš€ DSA with C – Day 1: Introduction & Setup ๐ŸŽฏ Goal: Understand what DSA is. Set up your C environment. Write your first C program. Learn about time & space complexity (theory). Practice basic input/output and loops. ๐Ÿง  Theory: What is DSA? Data Structures = Ways to organize and store data efficiently. Algorithms = Step-by-step instructions to solve problems. Why DSA matters: Faster apps, better problem-solving, cracking tech interviews. ๐Ÿ”ง Setup for C Programming Install a C compiler: Windows : Use Code::Blocks or install MinGW and use VS Code. Mac/Linux : Already comes with gcc . Use VS Code or terminal. Create your first .c file. ๐Ÿ‘จ‍๐Ÿ’ป Hello World Program # include <stdio.h> int main () { printf ( "Hello, World!\n" ); return 0 ; } Compile using: gcc hello.c -o hello ./hello ๐Ÿ“š Time & Space Complexity (Intro) Big O Notation (O(n), O(1), etc.) Example: Loop runs n times → ...