Posts

simple c logic

 simple c  lan some program logics C simple logic code for preparation : //reverse of number #include void main() { int n = 123, rev = 0; while (n > 0) { rev = rev * 10 + n % 10; n = n / 10; printf("%d", rev); } // palindrome int n = 121, temp = n, rev = 0; while (n > 0) { rev = rev * 10 + n % 10; n /= 10; } if (rev == temp) printf("Palindrome"); else printf("Not Palindrome"); //table int n = 5; for (int i = 1; i <= 10; i++) printf("%d x %d = %d\n", n, i, n*i); //summ of n numbers int n = 10 int sum = n * (n + 1) / 2 printf("%d", sum) //count digits int n = 4567, count = 0; while (n > 0) { count++; n /= 10; } printf("%d", count); //sum of even int sum = 0; for (int i = 1; i <= 100; i++) { if (i % 2 == 0) sum += i; } printf("%d", sum); //sum of array int a[] = {1, 2, 3, 4, 5}, sum = 0; for (int i = 0; i < 5; i++) sum += a[i]; //largest element ...

Important questions in c language 2units

Functions in c

C Functions Interactive Learning Functions in C - Interactive Learning 1. What is a Function? A function is a block of code that performs a specific task. Functions help in code reusability and better structure. 2. Function Declaration (Prototype) Syntax: return_type function_name(parameters); Example: int add(int a, int b); 3. Function Definition Syntax: return_type function_name(parameters) { // body of the function return value; } Example: int add(int a, int b) { return a + b; } 4. Function Call Syntax: function_name(arguments); Example: #include <stdio.h> int add(int, int); int main() { int result = add(5, 10); printf("Sum = %d", result); return 0; } 5. Built-in (Library) Functions These are pre-defined functions in header files. Examples: ...

ARRAYS IN C

Image
Array Concept in C Array Concept in C Understanding Arrays with Examples, Memory Representation, and Operations 📌 What is an Array? An array is a collection of similar data types stored in contiguous memory locations. It allows storing multiple values under a single name, and each value is accessed using an index. int a[5]; // array of 5 integers ⭐ Features of Arrays Stores multiple values of the same data type. Memory is allocated contiguously. Access using an index (starts from 0). Provides random access to elements. Fixed size (decided at compile time). 📝 Declaration & Initialization int marks[5]; int marks[5] = {10, 20, 30, 40, 50}; int marks[] = {10, 20, 30, 40, 50}; ➡️ Accessing Elements printf("%d", marks[0]); // 10 printf(...

Looping statements in c

Looping Statements in C 🔁 Looping Statements in C Loops allow repeating code multiple times until a condition is satisfied. 1️⃣ for Loop 📘 Full Definition The for loop is used when the number of iterations is known in advance. It combines initialization, condition, and increment/decrement in a single line. ⚡ Shortcut: Best for fixed repetitions. 🔹 Syntax: for(initialization; condition; update) { // code to execute } Show Example #include <stdio.h> int main() { for (int i = 1; i 2️⃣ while Loop 📘 Full Definition The while loop is used when the number of iterations is not known in advance. It keeps executing as long as the condition is true. ⚡ Shortcut: Repeat while condition is true. 🔹 Syntax: while(condition) { // code to execute } ...

Conditional statements in C

Conditional Statements in C ✨ Conditional Statements in C Conditional statements help control the flow of a program based on conditions. 1️⃣ if Statement 📘 Full Definition The if statement in C is used to execute a block of code only when a given condition is true. If the condition evaluates to false, the code inside the if block is skipped. ⚡ Shortcut Definition if = Runs code only when condition is true. 📝 Syntax if (condition) { // statements; } Show Example #include <stdio.h> int main() { int age = 18; if (age >= 18) { printf("You are eligible to vote."); } return 0; } 2️⃣ if-else Statement 📘 Full Definition The if-else statement provides two alternative paths of execution. If the condition is true,...

C syllabus for beginners

Image
C Language Syllabus 📘 C Language Syllabus Outline Unit 1: Introduction to C History and Importance of C Structure of a C Program Compilation and Execution Process printf() and scanf() Functions Simple C Programs (Hello World, Sum of Numbers) Unit 2: Operators and Expressions Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Increment/Decrement Operators Conditional (Ternary) Operator Operator Precedence and Associativity Unit 3: Control Structures if, if-else, nested if-else switch-case statement for loop while loop do-while loop break and continue goto statement Unit 4: Functions in C Definition and Declaration Types of Func...