Posts

Showing posts from November, 2026

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 ...

C Programs to demonstrate use of break Statement in All Three types of Loops (for, while and do while loop)

The break statement terminates a loop immediately when the specified condition becomes true. C में break statement condition true होने पर loop को तुरंत terminate कर देता है। Syntax break; 1. break 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++) { printf("%d\n", i); if (i == 7) break; } return 0; } Output Counting from 1 to 10 1 2 3 4 5 6 7 Effect: When i becomes 7, break terminates the for loop. Numbers 8, 9, and 10 are not printed. जब i की value 7 होती है, तो break for loop को terminate कर देता है। 8, 9 और 10 print नहीं होते। 2. break Statement in while Loop C Program #include <stdio.h> int main() { int i = 1; printf("Counting from 1 to 10\n"); while (i <= 10) { printf("%d\n", i); if (i == 7) break; i++; } return 0; ...

C Program to demonstrate use of break Statement in switch case

The break statement terminates a switch case and transfers control outside the switch statement. C में break statement किसी matching case को execute करने के बाद switch statement से बाहर निकलता है। Syntax break; C Program #include <stdio.h> int main() { int day; printf("Enter day number (1-7): "); scanf("%d", &day); switch (day) { case 1: printf("Monday"); break; case 2: printf("Tuesday"); break; case 3: printf("Wednesday"); break; case 4: printf("Thursday"); break; case 5: printf("Friday"); break; case 6: printf("Saturday"); break; case 7: printf("Sunday"); break; default: printf("Wrong input!"); } return 0; } Output Enter day number (1-7): 3 Wednesday Explanation The switch statement checks the value of day and displays the corresponding weekday. The break statement s...

C Programs to Print Pyramid Patterns Using Nested Loops

In C programming, pattern programs are commonly used to understand nested loops. These programs print different patterns of stars, numbers, and alphabets using for loops. A nested loop is a loop inside another loop. The outer loop controls the number of rows, while the inner loop controls the number of characters, numbers, or spaces printed in each row. C Programming में Pattern Programs का उपयोग Nested Loops को समझने के लिए किया जाता है। इन programs की सहायता से हम Stars, Numbers और Alphabets के विभिन्न patterns print कर सकते हैं। Nested Loop एक ऐसा loop होता है जिसके अंदर दूसरा loop होता है। Outer Loop rows को नियंत्रित करता है, जबकि Inner Loop प्रत्येक row में print होने वाले characters, numbers या spaces की संख्या को नियंत्रित करता है। Basic Structure of Nested Loops for (i = 1; i <= rows; i++) { for (j = 1; j <= columns; j++) { // Print pattern } printf("\n"); } Nested Loops का Basic Structure for (i = 1; i <= rows; i++) { for (j = ...