Posts

C Programming Tutorials – Complete Guide from Basics to Advanced

Welcome to C Tutorials MP , a learning resource for students who want to learn C programming step by step. Explore the topics below, read the explanations, practise programs, and strengthen your programming fundamentals. How to use this guide: Start with Section 1 and continue in order. Click any topic to open its dedicated tutorial. We will keep this index updated as more lessons are added. 1. Introduction to C Programming Introduction to C Programming History and Features of C Applications and Advantages of C Structure of a C Program Writing and Executing Your First C Program Compiler, Interpreter and IDE 2. Tokens, Variables and Data Types Tokens in C Keywords and Identifiers Variables and Constants Data Types in C Declaration and Initialization of Variables Type Conversion and Type Casting 3. Input, Output and Operators printf() and scanf() Functions Operators in C Arithmetic and Relational Operators Logical and Assignment Operators Increment and Decrement Operators Operator Prece...

Rainbow Program in C Language (C में इंद्रधनुष बनाने का प्रोग्राम)

Image
The Rainbow program in C uses graphics functions to draw a beautiful rainbow on the screen. It demonstrates the use of arcs, colors, loops, and graphics functions in C programming. C भाषा में Rainbow प्रोग्राम Graphics Functions की सहायता से स्क्रीन पर इंद्रधनुष बनाता है। यह प्रोग्राम Arcs, Colors, Loops तथा Graphics Functions के उपयोग को समझने में मदद करता है। C Program #include <stdio.h> #include <graphics.h> #include <conio.h> #include <dos.h> void rainbow() { int gd = DETECT, gm; int x, y, i; int colors[] = { RED, LIGHTRED, YELLOW, GREEN, LIGHTCYAN, BLUE, MAGENTA }; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); x = getmaxx() / 2; y = getmaxy() / 2; for (i = 0; i < 7; i++) { setcolor(colors[i]); arc(x, y, 0, 180, 60 + i * 20); delay(300); } getch(); closegraph(); } int main() { rainbow(); return 0; } Output The program displays seven colored semicir...

Moving Car Program in C Language (C में चलती हुई कार का प्रोग्राम)

Image
The Moving Car program in C is a graphics-based program that demonstrates animation using graphics functions. It draws a car and moves it from left to right on the screen. C भाषा में Moving Car प्रोग्राम एक Graphics-Based प्रोग्राम है, जो Graphics Functions की सहायता से Animation प्रदर्शित करता है। यह स्क्रीन पर एक कार बनाता है और उसे बाएँ से दाएँ चलाता है। C Program #include <graphics.h> #include <conio.h> #include <dos.h> int main() { int i; int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); outtextxy(25, 240, "Press any key to view the moving car"); getch(); for (i = 0; i <= 420; i += 10) { cleardevice(); /* Draw car body */ setcolor(RED); rectangle(50 + i, 275, 150 + i, 350); rectangle(150 + i, 315, 200 + i, 350); /* Draw wheels */ setcolor(WHITE); circle(75 + i, 360, 10); ...

C Programs to Calculate HCF and LCM of Two Numbers

HCF and LCM are important mathematical concepts used in programming. HCF is the greatest number that divides two numbers exactly, while LCM is the smallest positive number divisible by both numbers. HCF और LCM गणित की महत्वपूर्ण अवधारणाएँ हैं। HCF वह सबसे बड़ी संख्या है जो दो संख्याओं को पूरी तरह विभाजित करती है, जबकि LCM वह सबसे छोटी धनात्मक संख्या है जो दोनों संख्याओं से विभाजित होती है। C Program to Calculate HCF:- Formula HCF (Highest Common Factor) is calculated using the Euclidean algorithm. C Program #include <stdio.h> int main() { int a, b, divisor, rem; printf("Enter two integer numbers: "); scanf("%d%d", &a, &b); while (b != 0) { rem = a % b; a = b; b = rem; } printf("HCF = %d", a); return 0; } Sample Output Enter two integer numbers: 12 18 HCF = 6 Explanation (English) The program uses the Euclidean algorithm to calculate HCF. It repeatedly divides the first number by the...

C Program to calculate nPr (Permutation) and nCr (Combination) using loop

1.) nPr (Permutation):- Permutation is used to calculate the number of ways to arrange r objects selected from n objects, where order is important. Formula nPr = n! / (n − r)! C Program #include <stdio.h> int main() { long int n, r, i; long int factn = 1, factnr = 1; long int npr; printf("Enter positive integer value of n: "); scanf("%ld", &n); printf("Enter positive integer value of r: "); scanf("%ld", &r); if (n >= r && r >= 0) { for (i = 1; i <= n; i++) factn = factn * i; for (i = 1; i <= n - r; i++) factnr = factnr * i; npr = factn / factnr; printf("nPr value = %ld", npr); } else { printf("Invalid input! Ensure n >= r >= 0."); } return 0; } Sample Output Enter positive integer value of n: 5 Enter positive integer value of r: 2 nPr value = 20 Explanation (English) ...

C Program to Demonstrate Forward Branching Using goto Statement

The goto statement transfers program control to a specified label. When control moves to a label located later in the program, it is called forward branching. C में goto statement program control को किसी specified label पर transfer करता है। जब control program में आगे स्थित label पर जाता है, तो इसे Forward Branching कहते हैं। Syntax Statement(s); goto Label; Statement(s); Label: Example: C Program to Calculate Square Root of a Positive Number C Program #include <stdio.h> #include <math.h> int main() { int n; float s; printf("Enter a positive integer: "); scanf("%d", &n); if (n <= 0) goto XYZ; s = sqrt(n); printf("Square root of %d = %f\n", n, s); XYZ: return 0; } Output 1 Enter a positive integer: 25 Square root of 25 = 5.000000 Output 2 Enter a positive integer: -5 Explanation The program accepts a positive integer from the user. If the entered number is zero or negative, the goto XYZ; statement...

C Program to Demonstrate Backward Branching Using goto Statement

The goto statement is used to transfer control from one part of a program to another specified label. When control moves to a previous label, it is called backward branching. C में goto statement का उपयोग program के control को किसी specified label पर transfer करने के लिए किया जाता है। जब control किसी पहले वाले label पर जाता है, तो इसे Backward Branching कहते हैं। Syntax Statement(s); Label: Statement(s); goto Label; Example: C Program to Calculate Square Root of a Positive Number C Program #include <stdio.h> #include <math.h> int main() { int n; float s; XYZ: printf("Enter a positive integer: "); scanf("%d", &n); if (n <= 0) goto XYZ; s = sqrt(n); printf("Square root of %d = %f\n", n, s); return 0; } Output Enter a positive integer: -5 Enter a positive integer: 0 Enter a positive integer: 25 Square root of 25 = 5.000000 Explanation The program asks the user to enter a positive integer. If the...

C Programs to demonstrate use of continue statement in All three types of Loops (for, while and do while loop), Difference Between break and continue

The continue statement skips the remaining statements of the current iteration and continues with the next iteration of the loop. C में continue statement current iteration के बाकी statements को skip करके loop की अगली iteration शुरू करता है। Syntax continue; 1. continue Statement in for Loop C Program #include <stdio.h> int main() { int i; printf("Counting from 1 to 10\n"); for (i = 1; i <= 10; i++) { if (i == 7) continue; printf("%d\n", i); } return 0; } Output Counting from 1 to 10 1 2 3 4 5 6 8 9 10 Effect: When i becomes 7, continue skips the printf() statement. Therefore, 7 is not printed, but the loop continues. जब i की value 7 होती है, तो continue printf() statement को skip कर देता है। इसलिए 7 print नहीं होता, लेकिन loop चलता रहता है। 2. continue Statement in while Loop C Program #include <stdio.h> int main() { int i = 0; printf("Counting from 1 to 10\n"); while ...