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

Enumeration (enum) in C Language – Definition, Syntax and Examples एनुमरेशन (एनम) यूजर डिफाइंड डेटा टाइप

Introduction to Enumeration (एनुमरेशन का परिचय) Enumeration is a user-defined data type in C language. It is used to define a collection of named integer constant values. These constant values are represented by meaningful names, which makes a program easier to understand and maintain. एनुमरेशन (Enumeration) C लैंग्वेज का एक यूजर डिफाइंड डाटा टाइप है। इसका प्रयोग विभिन्न इंटीजर अचर राशियों (Integer Constant Values) को उनके नाम के साथ परिभाषित करने के लिए किया जाता है। Enumeration में प्रत्येक constant को एक नाम दिया जाता है। इन नामों का प्रयोग प्रोग्राम में integer constant values के स्थान पर किया जा सकता है। इससे प्रोग्राम को समझना और उसमें बदलाव करना आसान हो जाता है। Enumeration को बनाने के लिए C लैंग्वेज में enum keyword का प्रयोग किया जाता है। For example, if we want to represent the days of a week, we can define an enumeration as follows: enum week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }; इस उदाहरण में week एक enumeration ty...

C Program to Find the Roots of a Quadratic Equation द्विघात समीकरण के मूल ज्ञात करने का C प्रोग्राम

A quadratic equation is an equation of the form: द्विघात समीकरण वह समीकरण है जिसका सामान्य रूप इस प्रकार होता है: ax^2+bx+c=0 Here, (a), (b), and (c) are coefficients, and (a) must not be zero. यहाँ (a), (b) और (c) गुणांक हैं तथा (a) का मान शून्य नहीं होना चाहिए। The roots of a quadratic equation can be calculated using the quadratic formula. द्विघात समीकरण के मूल ज्ञात करने के लिए निम्नलिखित सूत्र का उपयोग किया जाता है: [x1=-b+sqrt({b^2-4ac}/{2a}), x2=-b-sqrt({b^2-4ac}/{2a})] Discriminant (विविक्तकर) The discriminant is represented by (D) and is calculated as: विविक्तकर को (D) से दर्शाया जाता है और इसकी गणना इस प्रकार की जाती है: [D=b^2-4ac] The value of the discriminant determines the nature of the roots. विविक्तकर का मान समीकरण के मूलों की प्रकृति निर्धारित करता है। If (D>0): The roots are real and distinct. यदि (D>0), तो मूल वास्तविक और असमान होते हैं। If (D=0): The roots are real and equal. यदि (D=0), तो मूल वास्तविक और समान होते हैं। If (D<0): The roots are complex co...

C Program to Find Profit, Loss or No Profit No Loss लाभ, हानि या न लाभ न हानि ज्ञात करने का C प्रोग्राम

When a product is purchased at a certain price and sold at another price, we can determine whether a profit or loss has occurred by comparing the cost price and selling price. जब कोई वस्तु एक निश्चित कीमत पर खरीदी जाती है और दूसरी कीमत पर बेची जाती है, तो क्रय मूल्य और विक्रय मूल्य की तुलना करके लाभ या हानि ज्ञात की जा सकती है। Cost Price (CP): The price at which a product is purchased. क्रय मूल्य (CP): वह मूल्य जिस पर कोई वस्तु खरीदी जाती है। Selling Price (SP): The price at which a product is sold. विक्रय मूल्य (SP): वह मूल्य जिस पर कोई वस्तु बेची जाती है। Formulas (सूत्र) Profit (लाभ) = Selling Price − Cost Price , when SP > CP. Loss (हानि) = Cost Price − Selling Price , when CP > SP. No Profit, No Loss (न लाभ, न हानि) , when SP = CP. C Program #include <stdio.h> int main(void) { float sp, cp, pl; printf("Enter Cost Price and Selling Price: "); scanf("%f %f", &cp, &sp); pl = sp - cp; if (pl > 0) { pri...

C Program to Print the State of Water According to Temperature तापमान के अनुसार पानी की अवस्था प्रिंट करने का C प्रोग्राम

Water can exist in three common states: solid (ice), liquid (water), and gas (steam or water vapour). Its state changes according to temperature and pressure. पानी मुख्य रूप से तीन अवस्थाओं में पाया जाता है: ठोस (बर्फ), द्रव (पानी) और गैस (भाप या जलवाष्प)। तापमान और दबाव के अनुसार पानी की अवस्था बदलती है। At normal atmospheric pressure, ice melts at 0°C and water boils at approximately 100°C. This program accepts the temperature in Celsius and displays the corresponding state of water. सामान्य वायुमंडलीय दबाव पर बर्फ 0°C पर पिघलती है और पानी लगभग 100°C पर उबलता है। यह प्रोग्राम Celsius में तापमान इनपुट लेकर पानी की अवस्था प्रदर्शित करता है। C Program #include <stdio.h> int main(void) { float temp; printf("Enter Temperature in Celsius: "); scanf("%f", &temp); if (temp <= 0) { printf("ICE\n"); } else if (temp < 100) { printf("WATER\n"); } else { printf("STEA...

C Program to Calculate Gross Salary of an Employee कर्मचारी का सकल वेतन ज्ञात करने का प्रोग्राम

In C language, the gross salary of an employee can be calculated by adding the basic salary and various allowances such as Travel Allowance (TA), Dearness Allowance (DA), and House Rent Allowance (HRA). सी लैंग्वेज में कर्मचारी का सकल वेतन (Gross Salary) ज्ञात करने के लिए मूल वेतन (Basic Salary) में विभिन्न भत्तों जैसे यात्रा भत्ता (TA), महँगाई भत्ता (DA) तथा मकान किराया भत्ता (HRA) को जोड़ा जाता है। Formula सूत्र: For this program, assume that: DA = 25% of Basic Salary TA = 20% of Basic Salary HRA = 10% of Basic Salary Gross Salary = Basic Salary + TA + DA + HRA इस प्रोग्राम में मान लिया गया है कि DA मूल वेतन का 25%, TA मूल वेतन का 20% तथा HRA मूल वेतन का 10% है। C Program #include <stdio.h> int main(void) { float gs, bs, ta, da, hra; printf("Enter basic salary: "); scanf("%f", &bs); da = (25 * bs) / 100; ta = (20 * bs) / 100; hra = (10 * bs) / 100; gs = bs + ta + da + hra; printf("\nBasic Salary = %.2f\n", b...

C Program to Find Square, Cube and Square Root of a Number किसी संख्या का वर्ग, घन एवं वर्गमूल ज्ञात करने का प्रोग्राम

In C language, mathematical functions are used to calculate the square, cube, and square root of a number. The pow() function calculates powers, while the sqrt() function calculates the square root. सी लैंग्वेज में किसी संख्या का वर्ग, घन तथा वर्गमूल ज्ञात करने के लिए गणितीय फंक्शन्स का प्रयोग किया जाता है। pow() फंक्शन किसी संख्या की घात ज्ञात करता है, जबकि sqrt() फंक्शन वर्गमूल ज्ञात करता है। Formulas सूत्र: Square (वर्ग): (n^2 = n \times n) Cube (घन): (n^3 = n \times n \times n) Square Root (वर्गमूल): (\sqrt{n}) C Program #include <stdio.h> #include <math.h> int main(void) { float n, square, cube, sr; printf("Enter a number: "); scanf("%f", &n); square = pow(n, 2); cube = pow(n, 3); printf("Square of %.2f = %.2f\n", n, square); printf("Cube of %.2f = %.2f\n", n, cube); if (n >= 0) { sr = sqrt(n); printf("Square root of %.2f = %.2f\n", n, sr); } else...

C Program to Swap Values of Two Variables Without Using a Third Variable तीसरे वेरिएबल का प्रयोग किए बिना दो वेरिएबल्स की वैल्यू स्वैप करने का प्रोग्राम

In C language, swapping means exchanging the values of two variables. We can swap two numerical variables without using a third variable by applying addition and subtraction operations. सी लैंग्वेज में स्वैपिंग का अर्थ दो वेरिएबल्स की वैल्यू को आपस में बदलना होता है। जोड़ तथा घटाव की गणितीय क्रियाओं का प्रयोग करके तीसरे वेरिएबल के बिना भी दो संख्यात्मक वेरिएबल्स की वैल्यू स्वैप की जा सकती है। C Program #include <stdio.h> int main(void) { float a, b; printf("Enter two values:\n"); scanf("%f %f", &a, &b); printf("Before swapping: a = %.2f, b = %.2f\n", a, b); a = a + b; b = a - b; a = a - b; printf("After swapping: a = %.2f, b = %.2f\n", a, b); return 0; } Output Enter two values: 10 20 Before swapping: a = 10.00, b = 20.00 After swapping: a = 20.00, b = 10.00 Explanation व्याख्या Suppose a = 10 and b = 20 . The following operations swap their values: मान लीजिए a = 10 तथा b = 20 हैं। निम्...