Category: C Language

  • C Programming – Operators – Part 1

    • Ex 1 : Modulo (%) Operator
    • Ex 2 : Arithmetic Operations (Integer Values)
    • Ex 3 : Arithmetic Operations (Float Values)
    • Ex 4 : Arithmetic Operation (With Using Variable)
    • Ex 5 : Addition Operator (Character Variable)
    • Ex 6 : To get student mark with out scanf function-I
    • Ex 7 : To get student mark with out scanf function-II
    • Ex 8 : To get student mark with scanf function-III
    • Ex 9 : Area of Circle
    • Ex 10 :Salary Calculation
    • Ex 11 :Conversion-kilometer to Centimeter,feet,inches,meter
    • Ex 12 :Fahrenheit and Celsius temperature conversion :
    • Ex 13 :Write a program to interchange values
    • Ex 14 :To Sum of Digits (3 Digit Number)

    Example : 1 Modulo (%) Operator;

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b;
    clrscr();
    a=7;
    b=2;
    c=a%b;
    printf(“Ans=%d”,c);
    c=a/b;
    printf(“Ans=%d”,c);
    getch();
    }

    Output :

    Ans=1
    Ans=3


    Go Top

    Example : 2 Arithmetic Operations (Integer Values)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a=7,b=2;
    clrscr();
    printf(“\nSum of A,B=%d”,a+b);
    printf(“\nSubtraction of A,B=%d”,a-b);
    printf(“\nMultiplication of A,B=%d”,a*b);
    printf(“\nDivision of A,B=%d”,a/b);
    printf(“\nModulo Division of A,B=%d”,a%b);
    printf(“\nAll Arithmetic Operations of A,B =%d”,((a+b)*(a-b)/5)%2);
    getch();
    }

    Output :

    Sum of A,B=9
    Subtraction of A,B=5
    Multiplication of A,B=14
    Division of A,B=3
    Modulo Division of A,B=1
    All Arithmatic Operations of A,B =1


    Go Top

    Example : 3 Arithmetic Operations (Float Values)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float a=7,b=2;
    clrscr();
    printf(“\nSum of A,B=%f”,a+b);
    printf(“\nSum of A,B=%.2f”,a+b);
    printf(“\nSubtraction of A,B=%.2f”,a-b);
    printf(“\nMultiplication of A,B=%.2f”,a*b);
    printf(“\nDivision of A,B=%.2f”,a/b);

    /* This line not worked ————–

    printf(“\nModulo Division of A,B=%.2f”,a%b);

    ———————————–*/

    printf(“\nAll Arithmatic Operations of A,B =%.2f”,(a+b)*(a-b)/5);
    getch();
    }

    Output :

    Sum of A,B=9.000000
    Sum of A,B=9.00
    Subtraction of A,B=5.00
    Multiplication of A,B=14.00
    Division of A,B=3.50
    All Arithmatic Operations of A,B =9.00


    Go Top

    Example : 4 Arithmetic Operation (With Using Variable)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b,sum,sub,mult,div,remind;
    clrscr();
    a=10;
    b=3;
    sum=a+b;
    sub=a-b;
    mult=a*b;
    div=a/b;
    remind=a%b;
    printf(“\nSum = %d”,sum);
    printf(“\nSubtraction = %d”,sub);
    printf(“\nMultiplication = %d”,mult);
    printf(“\nDivision=%d”,div);
    printf(“\nModulo Division = %d”,remind);
    getch();
    }

    Output :

    Sum = 13
    Subtraction = 7
    Multiplication = 30
    Division=3
    Modulo Division = 1


    Go Top

    Example : 5 Addition Operator (Character Variable)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char c1,c2;
    clrscr();
    c1=’a’;
    c2=’b’;
    printf(“\n%d”,c1); /* It Prints ascii value of a */
    printf(“\n%d”,c2);
    printf(“\n%d”,c1+c2);
    getch();
    }

    Output :

    97
    98
    195


    Go Top

    Example : 6 To get student mark with out scanf function-I

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float m1,m2,m3;
    clrscr();
    m1=80;
    m2=90;
    m3=100;
    printf(“\nSum of Marks = %.2f”,m1+m2+m3);
    printf(“\nAverage of Marks = %.2f”,(m1+m2+m3)/3);
    getch();
    }

    Output :

    Sum of Marks = 270.00
    Average of Marks = 90.00


    Go Top

    Example : 7 To get student mark with out scanf function-II

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float m1,m2,m3,tot,avrg;
    clrscr();
    m1=80;
    m2=90;
    m3=100;
    tot=m1+m2+m3;
    avrg=tot/3;
    printf(“\nSum of Marks = %.2f”,tot);
    printf(“\nAverage of Marks = %.2f”,avrg);
    getch();
    }

    Output :

    Sum of Marks = 270.00
    Average of Marks = 90.00

    Go Top

    Example : 8 To get student mark with scanf function-III

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float m1,m2,m3,tot,avrg;
    clrscr();
    printf(“\nEnter Mark 1=”);
    scanf(“%f”,&m1);
    printf(“\nEnter Mark 2=”);
    scanf(“%f”,&m2);
    printf(“\nEnter Mark 3=”);
    scanf(“%f”,&m3);
    tot=m1+m2+m3;
    avrg=tot/3;
    printf(“\nSum of Marks = %.2f”,tot);
    printf(“\nAverage of Marks = %.2f”,avrg);
    getch();
    }

    Output :

    Enter Mark 1=100
    Enter Mark 2=90
    Enter Mark 3=100

    Sum of Marks = 290.00
    Average of Marks = 96.67


    Go Top

    Example : 9 Area of Circle :

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float radius,area;
    clrscr();
    printf(“\nEnter Radius of Circle : “);
    scanf(“%f”,&radius);
    area=3.14*radius*radius;
    printf(“\nArea of Circle = %.2f”,area);
    getch();
    }

    Output :

    EEnter Radius of Circle : 2
    Area of Circle = 12.56


    Go Top

    Example : 10 Salary Calculation :

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float salary,allowance,deduction;
    clrscr();
    printf(“\nEnter Ganesh’s Basic Salary = “);
    scanf(“%f”,&salary);
    allowance=salary*(10.0/100); /* 10% of Basic Salary */
    deduction=salary*(20.0/100); /* 3% of Basic Salary */
    printf(“\nAllowance of Salary Rs.=%.2f”,allowance);
    printf(“\nDeduction of Salary Rs.=%.2f”,deduction);
    printf(“\nNet Salary = %.2f”,salary+allowance-deduction);
    getch();
    }

    Output : 1

    Enter Ganesh’s Basic Salary = 2000

    Allowance of Salary Rs.=200.00
    Deduction of Salary Rs.=400.00
    Net Salary = 1800.00


    Go Top

    Example : 11 Conversion kilometer to Centimeter,feet,inches,meter.

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float km;
    clrscr();
    printf(“Enter Kilometer Value = “);
    scanf(“%f”,&km);
    printf(“\n%.2f Kilo Meter = %.2f Centimeter”,km,100000*km);
    printf(“\n%.2f Kilo Meter = %.2f Feet”,km,km*3280.839895);
    printf(“\n%.2f Kilo Meter = %.2f Inches”,km,km*39370.07874);
    printf(“\n%.2f Kilo Meter = %.2f Meter”,km,km*1000);
    getch();
    }
    /*
    Note :
    1 Km = 1000 meter
    1 Km = 3280.839 895 feet
    1 kilometer = 39370.078 74 inch
    1 kilometer = 100000 centimeter
    */

    Output :

    Enter Kilometer Value = 3

    3.00 Kilo Meter = 300000.00 Centimeter
    3.00 Kilo Meter = 9842.52 Feet
    3.00 Kilo Meter = 118110.24 Inches
    3.00 Kilo Meter = 3000.00 Meter


    Go Top

    Example : 12 Fahrenheit and Celsius temperature conversion :

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float fh,cel;
    clrscr();
    printf(“\nEnter Faherenheit Value = “);
    scanf(“%f”,&fh);
    cel= ((fh-32)/9.0 )*5;
    printf(“\nCelsius Value = %.2f”,cel);
    getch();
    }

    /* Note :

    To convert Fahrenheit temperatures into Celsius:

    * Begin by subtracting 32 from the Fahrenheit number.
    * Divide the answer by 9.
    * Then multiply that answer by 5.
    */

    Output :

    Enter Faherenheit Value = 50

    Celsius Value = 10.00


    Go Top

    Example : 13 Write a program to interchange values

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b,t;
    clrscr();
    printf(“\nEnter First Value = “);
    scanf(“%d”,&a);
    printf(“\nEnter Second Value = “);
    scanf(“%d”,&b);
    printf(“\nBefore Swap a = %d,b=%d”,a,b);
    t=b;
    b=a;
    a=t;
    printf(“\nAfter Swap a=%d,b=%d”,a,b);
    getch();
    }

    Output :

    Enter First Value = 2
    Enter Second Value = 3

    Before Swap a = 2,b=3
    After Swap a=3,b=2


    Go Top

    Example : 14 To Sum of Digits (3 Digit Number)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,s=0;
    clrscr();
    printf(“\nEnter Three Digit Value”);
    scanf(“%d”,&n);
    s=s+(n%10);
    n=n/10;
    s=s+(n%10);
    n=n/10;
    s=s+(n%10);
    printf(“\nSum of Digits = %d”,s);
    getch();
    }

    Output :

    Enter Three Digit Value 123
    Sum of Digits = 6

  • C Programming Basic Simple Programs

    C Language – Basic Programs

    • Ex 1 : My First Basic Program -I
    • Ex 2 : My First Basic Program -II
    • Ex 3 : My First Basic Program -III
    • Ex 4 : Integer & Float Converstion
    • Ex 5 : Floating Point Error..
    • Ex 6 : Variable Declaration
    • Ex 7 : Working With Variable
    • Ex 8 : Integer Variable With Scanf-I
    • Ex 9 : Integer Variable With Scanf-II
    • Ex 10 :Integer Variable With Scanf-III
    • Ex 11 :Integer Variable With Scanf-IV
    • Ex 12 :Character Variable Declaration
    • Ex 13 :String Variable With Scanf Function
    • Ex 14 :String Variable With gets Function
    • Ex 15 :Combine all Variables
    • Ex 16 :Print Employee Information with gotoxy function

    Example : 1 Write a Program to print “Hello”

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    /*My First Program – Comment Line */
    clrscr();
    printf(“Hello”);   
    getch();
    }

    Output :

    Hello


    Go Top

    Example : 2

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    printf(“Hello\nWelcome”);
    printf(“\nGoldenjrsinfo”);
    printf(“-My Web”);
    getch();
    }

    Output :

    Hello
    Welcome
    Goldenjrsinfo-MyWeb


    Go Top

    Example : 3

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    printf(“\nHello 12”);    
    printf(“\n%d”);       
    printf(“\n%d”,100);
    printf(“\nA=%d”,100);
    printf(“\nA=%d+10”,100);
    printf(“\nA=%d”,100+10);
    getch();
    }

    Output :

    Hello 12
    0
    100
    A=100
    A=100+10
    A=110


    Go Top

    Example : 4 Integer & Float Conversions (5/2)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    printf(“\n1-> %d”,5/2);
    printf(“\n2-> 5/2 = %d”,5/2);           

    /* printf(“\n5/2 = %f”,5/2); This Line is Error */

    printf(“\n3-> 5.0/2 = %d”,5.0/2);   
    printf(“\n4-> 5/0/2 = %f”,5.0/2);     
    printf(“\n5-> 5.0/2 = %.2f”,5.0/2);   
    printf(“\n6-> 5/2.0 = %.2f”,5/2.0);    
    printf(“\n7-> 5.0/2.0=%.2f”,5.0/2.0);
    getch();
    }

    Output :

    1-> 2
    2-> 5/2 = 2
    3-> 5.0/2 = 0
    4-> 5/0/2 = 2.500000
    5-> 5.0/2 = 2.50
    6-> 5/2.0 = 2.50
    7-> 5.0/2.0=2.50


    Go Top

    Example : 5 Floating Point Error….

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    printf(“\n5/2 = %f”,5/2);
    /*if Error found this program replace %f into %d”*/
    getch();
    }

    Output :(Press ALT+F9 to compile In Turboc & Press ALT+F5 to see below Message)

    printf : floating point formats not linked
    Abnormal program termination


    Go Top

    Example : 6 Variables…..

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a;
    clrscr();
    printf(“\n%d”,10);
    printf(“\n%d (Garbage Value)”,a);
    getch();
    }

    Output :

    10
    -28711  (Garbage Value)


    Go Top

    Example : 7 Variables…..

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a;
    clrscr();
    a=10;
    printf(“\n%d “,a);
    printf(“\nValue = %d”,a);
    printf(“\nGiven Value = %d”,a);
    getch();
    }

    Output :

    10
    Value = 10
    Given Value=10

    Go Top

    Example : 8 Integer Variable with scanf

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a;
    clrscr();
    /* a=10;*/
    scanf(“%d”,a);
    printf(“\n%d “,a);
    printf(“\nValue = %d”,a);
    getch();
    }

    Output :if You Type 20 from Keyboard

    20

    Press Enter…

    20
    Value = 20

    Finally…You can see Output window..

    20
    20
    Value = 20


    Go Top

    Example : 9 Integer Variable with scanf

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a;
    clrscr();
    printf(“\nEnter Any Value = “);
    scanf(“%d”,a);
    printf(“\nEntered Value = %d”,a);
    getch();
    }

    Output :

    Enter Any Value =

    if You Type 20 from Keyboard

    Enter Any Value = 20

    Press Enter…

    Entered Value = 20

    Finally…You can see Output window..

    Enter Any Value =20
    Entered Value = 20


    Go Top

    Example : 10 Working With scanf Function

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b;
    clrscr();
    scanf(“%d %d”,&a,&b);
    printf(“\n%d”,a);
    printf(“\n%d”,b);
    getch();
    }

     Output : 1

    if You type 10 from Keyboard

    10

    Press Enter > again please type 20 from Keyboard

    10

    20

    Finally…You can see Output window..

    10
    20
    10
    20

    Output : 2

    press 10 from Keyboard > press spacebar (Don’t Press Enter) > Press 20 from Spacebar

    10 20

    Press Enter >

    10 20

    Finally…You can see Output window..

    10 20
    10
    20


    Go Top

    Example : 11 Working With Scanf ..

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b;
    clrscr();
    printf(“\nEnter  a Value = “);
    scanf(“%d”,&a);
    printf(“\nEnter  b Value = “);
    scanf(“%d”,&b);
    printf(“\nA Value = %d”,a);
    printf(“\nB Value = %d”,b);
    printf(“\nA+B Value = %d”,a+b);
    printf(“\nA+10 Value = %d”,a+10);
    getch();
    }

    Output :

    Enter a Value =

    if You Type 20 from Keyboard

    Enter a Value = 10

    Press Enter…

    Enter a Value = 10

    Enter b Value = 10

    Press Enter…

    Finally…You can see Output window..

    Enter a Value = 10
    Enter b Value = 20
    A Value =10
    B Value= 20
    A+B Value = 30
    A+10 Value = 20


    Go Top

    Example : 12 Character Variable Declaration

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char ans;
    clrscr();
    printf(“\n ans = %c”,ans);
    ans=’ ‘;
    printf(“\n ans= %c”,ans);
    printf(“\n ans= %d”,ans); /*Returns ascii value of Space */
    ans=’Y’;
    printf(“\n ans = %c”,ans);
    getch();
    }

    Output :

    ans = Å
    ans=
    ans= 32
    ans = Y


    Go Top

    Example : 13 String Variable With Scanf Function

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char ans;
    char myname[15];
    clrscr();
    printf(“\nEnter Any Character => “);
    scanf(“%c”,&ans);
    printf(“\nEnter Any Name(String) => “);
    scanf(“%s”,&myname);
    printf(“\nGiven Character => %c”,ans);
    printf(“\nGiven Name => %s”,myname);
    getch();
    }

    Output :

    Enter Any Character => M

    Enter Any Name(String) => Manoj Kumar

    Given Character => M
    Given Name => Manoj


    Go Top

    Example : 14 String Variable With gets Function

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char ans;
    char myname[15];
    clrscr();

    printf(“\nEnter Any Name => “);
    scanf(“%s”,&myname);
    printf(“\nGiven Name Using Scanf => %s”,myname);

    /*
    Please add fflush(stdin) before gets function
    If Omitted this line,You will get wrong output
    If any doubt,remove the fflush(stdid); and run again
    */

    printf(“\nEnter Any Name => “);
    fflush(stdin);
    gets(myname);

    printf(“\nGiven Name Using gets => %s”,myname);
    getch();
    }

    Output :

    Enter Any Name => Vijay Antony

    Given Name Using Scanf => Vijay
    Enter Any Name => Vijaya Raj

    Given Name Using gets => Vijaya Raj


    Go Top

    Example : 15 Combine all variables (Emp Info)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {

    int empno;
    char empname[20];
    float salary;
    clrscr();
    printf(“\nGive the Employee Details”);

    printf(“\nEmployee ID = “);
    scanf(“%d”,&empno);

    printf(“\nEmployee Name =”);
    fflush(stdin);
    gets(empname);

    printf(“\nSalary = “);
    scanf(“%f”,&salary);

    printf(“\nGiven Emp Details “);
    printf(“\nEmp ID=%d , Empname= %s,Salary = %.2f”,empno,empname,salary);

    getch();
    }

    Output :

    Give the Employee Details
    Employee ID = 101

    Employee Name =Rakesh Sharma

    Salary = 24000

    Given Emp Details
    Emp ID=101 , Empname= Rakesh Sharma,Salary = 24000.00


    Go Top

    Example : 16 print employee information with gotoxy function (Read Carefully)

    /*Author : C.Saravana Kumar */
    #include<stdio.h>
    #include<conio.h>
    void main()
    {

    int empno;
    char empname[20];
    float salary;
    clrscr();

    /*Syntax of gotoxy function is > gotoxy(Xposition,Yposition) */
    /*
    ————————————– (x) |
    |            .(10,1)
    |
    |
    |             .(10,40)          .(60,40)
    (y)

    (10,1) Means > gotoxy(10,1);
    */
    gotoxy(2,2);printf(“Employee ID “);
    gotoxy(25,2);scanf(“%d”,&empno);

    gotoxy(2,4);printf(“Employee Name “);
    gotoxy(25,4);fflush(stdin);gets(empname);

    gotoxy(2,6);printf(“Salary “);
    gotoxy(25,6);scanf(“%f”,&salary);

    gotoxy(2,8);printf(“\nGiven Emp Details “);
    gotoxy(2,11);printf(“Emp No”);
    gotoxy(9,11);printf(“Emp Name”);
    gotoxy(32,11);printf(“Salary”);

    gotoxy(2,13);printf(“%d”,empno);
    gotoxy(9,13);printf(“%s”,empname);
    gotoxy(32,13);printf(“%.2f”,salary);

    getch();
    }

    Output :

    Employee ID                101

    Employee Name           Tamil Selvan

    Salary                         45000

    Given Emp Details

    Emp No   Emp Name                             Salary

    101        Tamil Selvan                           45000.00

  • C Programming – If Statements – Examples

    Examples of IF Statements

    Click the following Links to go Solutions of Programs :

    • 1.1 To Check Eligible to Vote – I
    • 1.2 To Check Eligible to Vote – II
    • 1.3 To Check Eligible to Vote – III
    • 2.1 Biggest of Two numbers – I
    • 2.2 Biggest of Two numbers – II
    • 2.3 Biggest of Two numbers – III
    • 3.1 Biggest of Three numbers – I
    • 3.2 Biggest of Three numbers – II
    • 3.3 Biggest of Three numbers – II
    • 4.1 To check given value is positive,negative or zero value.
    • 5.1 To check given number is Even or Odd number
    • 6.1 To Calculate the absolute value of an integer
    • 7.1 Leap Year or Not
    • 8.1 To categorizes a single character that is entered at the keyboard.
    • 9.1 To Evaluate simple expression of the following form – I : Number operator Number For Ex : See Following Output
    • Type in your expression : 10+20
    • 30.00
    • Ex:9.2 To Evaluate simple expression of the following form -II : Number operator Number

    Example : 1.1 To Check Eligible to Vote

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int age;
    clrscr();
    printf("\nEnter Your Age : ");
    scanf("%d",&age);
    
    if(age>=18)
       printf("\nAge is greater than or equal to 18");
    
    getch();
    }

    Output : 1

    Enter Your Age : 30
    Age is greater than or equal to 18

    Output : 2 (No Result)

    Enter Your Age : 10


    Example : 1.2 To Check Eligible to Vote

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int age;
    clrscr();
    printf("\nEnter Your Age : ");
    scanf("%d",&age);
    
    if(age>=18)
    {
       printf("\nAge is greater than or equal to 18");
       printf("\nThis Age Eligible to Vote");
    }
    
    getch();
    }

    Output : 1

    Enter Your Age : 30
    Age is greater than or equal to 18
    This Age Eligible to Vote

    Output : 2 (No Result)

    Enter Your Age : 10


    Example : 1.3 To Check Eligible to Vote

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int age;
    clrscr();
    printf("\nEnter Your Age : ");
    scanf("%d",&age);
    
    if(age>=18)
       printf("\nEligible to Vote");
    else
       printf("\nNot Eligible to Vote");
    
    getch();
    }

    Output : 1

    Enter Your Age : 30
    Age is greater than or equal to 18
    Eligible to Vote

    Output : 2 (No Result)

    Enter Your Age : 10
    Not Eligible to vote


    Example : 2.1 Biggest of Two Numbers

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b;
    clrscr();
    printf("\nEnter Value of A ");
    scanf("%d",&a);
    
    printf("\nEnter Value of B ");
    scanf("%d",&b);
    
    if(a>b)
       printf("\n A is Big");
    else
       printf("\n B is Big");
    
    getch();
    }

    Output : 1

    Enter value of A 10
    Enter value of B 20
    A is big

    Output : 2 (Result is Wrong – To Fix This Problem – See Next Example 2.2)

    Enter value of A 10
    Enter value of B 10
    B is big


    Go Top

    Example : 2.2 Biggest of Two Numbers (Change below Code in Previous Code ( Ex 2.1 )

    if(a>b)
       printf("\nA is Big");
    if(b>a)
       printf("\nB is Big");

    (Or)

    if(a>b)
       printf("\nA is Big");
    else if(b>a)
       printf("\nB is Big");

    Output : 1

    Enter value of A 10
    Enter value of b 20
    B is big

    Output : 2 (To print message A & B are equal – See the below Example 2.3

    Enter value of A 10
    Enter value of B 10


    Example : 2.3 Biggest of Two Numbers (Change below Code in Previous Code (Ex 2.1 )

    if(a>b)
       printf("\nA is Big");
    if(b>a)
       printf("\nB is Big");
    else if(a==b)
       printf("\nA & B are Equal");

    Output : 1

    Enter value of A 10
    Enter value of b 20
    B is big

    Output : 2

    Enter value of A 10
    Enter value of B 10
    A & B are Equal


    Example : 3.1 Biggest of Three Numbers

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b,c;
    clrscr();
    printf("\nEnter Value of A ");
    scanf("%d",&a);
    printf("\nEnter Value of B ");
    scanf("%d",&b);
    printf("\nEnter Value of C ");
    scanf("%d",&c);
    
    if(a>b && a>c)
       printf("\n%d is Big",a);
    else if (b>a && b>c)
       printf("\n%d is Big",b);
    else if (c>a && c>b)
       printf("\n%d is Big",c);
    
    getch();
    }

    Output : 1

    Enter Value of A 2
    Enter Value of B 3
    Enter Value of C 4
    4 is Big

    Output : 2 (A & C Values are less than B.See the Next Output )

    Enter Value of A 3
    Enter Value of B 4
    Enter Value of C 3
    4 is Big

    Output : 3 (A & C Values are greater than B. To print message A & C is big – See [Ex 3.2])

    Enter Value of A 3
    Enter Value of B 2
    Enter Value of C 3

    Output : 4 (To print message 3 values are Equal – See [Ex 3.2])

    Enter Value of A 3
    Enter Value of B 3
    Enter Value of C 3


    Example : 3.2 Biggest of Three Numbers (Change below code in Previous Code[(Ex 3.1 ] )

    if(a>b && a>c)
       printf("\n%d is Big",a);
    else if (b>a && b>c)
       printf("\n%d is Big",b);
    else if (c>a && c>b)
       printf("\n%d is Big",c);
    else
       printf("\n3 Values are Equal");

    [or]

    if(a>b && a>c)
       printf("\n%d is Big",a);
    else if (b>a && b>c)
       printf("\n%d is Big",b);
    else if (c>a && c>b)
       printf("\n%d is Big",c);
    else if(a==b && b==c)
       printf("\n3 Values are Equal");

    Output : 1

    Enter Value of A 3
    Enter Value of B 3
    Enter Value of C 3
    3 Values are Equal

    Output : 2 (A & C Values are greater than B. To print message A & C is big – See [Ex 3.3])

    Enter Value of A 3
    Enter Value of B 2
    Enter Value of C 3


    Example : 3.3 Biggest of Three Numbers (Finally)

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b,c;
    clrscr();
    printf(“\nEnter Value of A “);
    scanf(“%d”,&a);
    printf(“\nEnter Value of B “);
    scanf(“%d”,&b);
    printf(“\nEnter Value of C “);
    scanf(“%d”,&c);

    if(a==c && b<a)
        printf(“\nA & C Values are Big “);
    else if(a==b && c<a)
       printf(“\nA & B Values are Big”);
    else if(b==c && a<b)
       printf(“\nB & C Values are Big”);
    else if(a==b && b==c)
       printf(“\n3 Values are Equal.”);
    else if(a>b && a>c)
       printf(“\nA (%d) is Big”,a);
    else if (b>a && b>c)
       printf(“\nB (%d) is Big”,b);
    else if (c>a && c>b)
       printf(“\nC (%d) is Big”,c);

    getch();
    }

    Output : 1

    Enter Value of A 2
    Enter Value of B 3
    Enter Value of C 2
    B (3) is Big

    Output : 2

    Enter Value of A 3
    Enter Value of B 2
    Enter Value of C 3
    A & C values are Big


    Example : 3.1 Biggest of Three Numbers

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,b,c;
    clrscr();
    printf(“\nEnter Value of A “);
    scanf(“%d”,&a);
    printf(“\nEnter Value of B “);
    scanf(“%d”,&b);
    printf(“\nEnter Value of C “);
    scanf(“%d”,&c);

    if(a>b && a>c)
       printf(“\n%d is Big”,a);
    else if (b>a && b>c)
       printf(“\n%d is Big”,b);
    else if (c>a && c>b)
       printf(“\n%d is Big”,c);

    getch();
    }

    Output : 1

    Enter Value of A 2
    Enter Value of B 3
    Enter Value of C 4
    4 is Big

    Output : 2 (A & C Values are less than B.See the Next Output )

    Enter Value of A 3
    Enter Value of B 4
    Enter Value of C 3
    4 is Big

    Output : 3 (A & C Values are greater than B. To print message A & C is big – See [Ex 3.2])

    Enter Value of A 3
    Enter Value of B 2
    Enter Value of C 3

    Output : 4 (To print message 3 values are Equal – See [Ex 3.2])

    Enter Value of A 3
    Enter Value of B 3
    Enter Value of C 3


    Example : 3.2 Biggest of Three Numbers (Change below code in Previous Code[(Ex 3.1 ] )

    if(a>b && a>c)
       printf(“\n%d is Big”,a);
    else if (b>a && b>c)
       printf(“\n%d is Big”,b);
    else if (c>a && c>b)
       printf(“\n%d is Big”,c);
    else
       printf(“\n3 Values are Equal”);

    [or]

    if(a>b && a>c)
       printf(“\n%d is Big”,a);
    else if (b>a && b>c)
       printf(“\n%d is Big”,b);
    else if (c>a && c>b)
       printf(“\n%d is Big”,c);
    else if(a==b && b==c)
       printf(“\n3 Values are Equal”);

    Output : 1

    Enter Value of A 3
    Enter Value of B 3
    Enter Value of C 3
    3 Values are Equal

    Output : 2 (A & C Values are greater than B. To print message A & C is big – See [Ex 3.3])

    Enter Value of A 3
    Enter Value of B 2
    Enter Value of C 3


    5.1 To check given number is Even or Odd number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n;
    clrscr();
    printf(“\nEnter any Value “);
    scanf(“%d”,&n);

    if(n%2==0)
       printf(“\n%d is Even Number “,n);
    else if (n%2==1)
       printf(“\n%d is Odd Number”,n);

    getch();
    }

    Output : 1

    Enter any Value 3
    3 is Odd Number


    6.1 To Calculate the absolute value of an integer

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int number;
    clrscr();
    printf (“Enter any Number “);
    scanf (“%d”, &number);

    if ( number < 0 )    number= – number;

    printf (“\n The absolute value is %d”,number);
    getch();
    }

    Output : 1

    Enter any Number 2
    The absolute value is 2

    Output : 2

    Enter any Number -4
    The absolute value is 4


    Ex:7.1 Leap Year or Not

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int year,reminder;
    clrscr();
    printf (“Enter the Year “);
    scanf (“%d”,&year);

    //if(year%4==0 && year%4!=0 || year % 400==0)
    //if((year%4==0 && year%4!=0) || year % 400==0)
    if(reminder==0)
       printf(“\nIt’s a Leap Year”);
    else
       printf(“\nIt’s not a Leap Year”);

    getch();
    }

    Output : 1

    Enter The year 2010
    It’s a Leap Year.


    Ex:8.1 to Categorizes a Single Character that is entered at the keyboard.

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char c;
    clrscr()
    printf(“\nEnter a Single Character > “);
    scanf(“%c”,&c);

    if ( (c >= ‘a’ && c <= ‘z’) || (c >= ‘A’ && c <=’Z’) )    printf (“It’s an alphabetic character.\n”); else if (c >= ‘0’ && c <= ‘9’ )    printf (“It’s a digit.\n”); else    printf (“It’s a special character.\n”);

    getch();
    }

    Output : 1

    Enter a Single Character > a
    It’s an alphabetic character.

    Output : 2

    Enter a Single Character > 2
    It’s a digit.

    Output : 3

    Enter a Single Character > &
    It’s a special character.


    Ex:9.1 To Evaluate simple expression of the following form – I : Number operator Number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float number1,number2;
    char operator;
    printf (“\nType in your expression : “);
    scanf(“%f %c %f”,&number1,operator,&number2);

    if ( operator == ‘+’ )
       printf (“\n%.2f “, number1+number2);
    else if ( operator == ‘-‘ )
       printf (“\n%.2f “, number1-number2);
    else if ( operator == ‘*’ )
       printf (“\n%.2f “, number1*number2);
    else if ( operator == ‘/’ )
       printf (“\n%.2f “, number1/number2);

    getch();
    }

    Output : 1

    Type in your expression : 10+20
    30.00

    Output : 2

    Type in your expression : 123.45*121
    14937.45

    Output : 3 (To Fix following Output See Next Example )

    Type in your expression : 5/0
    (Program terminated.Because Division by Zero Error)


    Ex:9.2 To Evaluate simple expression of the following form -II : Number operator Number

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float number1,number2;
    char operator;
    printf (“\nType in your expression : “);
    scanf(“%f %c %f”,&number1,operator,&number2);

    if ( operator == ‘+’ )
       printf (“\n%.2f “, number1+number2);
    else if ( operator == ‘-‘ )
       printf (“\n%.2f “, number1-number2);
    else if ( operator == ‘*’ )
       printf (“\n%.2f “, number1*number2);
    else if ( operator == ‘/’ )
    else if ( operator == ‘/’ )
    {
      if(number2==0)
         printf(“\nCannot divided by zero “);
      else
         printf (“\n%.2f “, number1/number2);
    }
    else
       printf(“\nUnknown Operator.);

    getch();
    }

    Output : 1

    Type in your expression : 5/0
    Cannot divided by zero

    Output : 2

    Type in your expression : 5$0
    Unknown Operator


  • Outline of C Language

    Learning C effectively involves a structured approach that covers basic to advanced concepts. Here’s a comprehensive outline to guide your learning journey:

    1. Introduction to C

    • Overview of C: Learn about C’s history, its uses, and why it’s influential.
    • Setting Up C: Install a C compiler (GCC, Clang) and set up a development environment (IDEs like Code::Blocks, Dev-C++, or Visual Studio Code).

    2. Basic Syntax and Operations

    • Hello, World!: Write your first C program.
    • Basic Syntax: Understand C’s syntax, semicolons, comments, and basic rules.
    • Data Types: Learn about C’s data types (int, float, double, char).
    • Variables: Declaration and initialization of variables.
    • Constants: Defining and using constants (#define and const).

    3. Control Structures

    • Conditional Statements: if, else if, else, and switch-case.
    • Loops: for, while, and do-while loops.
    • Control Flow Statements: break, continue, and goto.

    4. Functions

    • Defining Functions: Function declarations, definitions, and calling functions.
    • Parameters and Arguments: Passing arguments by value and by reference.
    • Scope and Lifetime: Understanding variable scope (local and global) and lifetime.

    5. Arrays and Strings

    • Arrays: Declaration, initialization, and manipulation of single-dimensional and multi-dimensional arrays.
    • Strings: String handling using arrays of characters and standard library functions (e.g., strcpy, strcat, strlen).

    6. Pointers

    • Basics of Pointers: Declaration, dereferencing, and pointer arithmetic.
    • Pointers and Arrays: Relationship between pointers and arrays.
    • Pointer to Pointer: Understanding double pointers.
    • Dynamic Memory Allocation: Using malloc, calloc, realloc, and free.

    7. Structures and Unions

    • Structures: Defining and using structures, accessing structure members.
    • Unions: Understanding unions and their uses.
    • Enums: Defining and using enumerations.

    8. Input and Output

    • Standard I/O: Using printf and scanf for formatted input and output.
    • File I/O: Reading from and writing to files using fopen, fclose, fread, fwrite, fprintf, and fscanf.

    9. Preprocessor Directives

    • Macros: Using #define for macros.
    • File Inclusion: Using #include to include header files.
    • Conditional Compilation: Using #if, #ifdef, #ifndef, #else, #elif, and #endif.

    10. Advanced Topics

    • Bit Manipulation: Using bitwise operators (&, |, ^, ~, <<, >>).
    • Memory Management: Understanding memory layout (stack vs. heap) and avoiding memory leaks.
    • Command-Line Arguments: Handling command-line arguments in main(int argc, char *argv[]).

    11. Data Structures

    • Linked Lists: Singly and doubly linked lists.
    • Stacks and Queues: Implementation and use cases.
    • Trees: Basic concepts of binary trees and binary search trees.
    • Graphs: Basic concepts and representation.

    12. Algorithms

    • Sorting Algorithms: Implementing and understanding bubble sort, selection sort, insertion sort, merge sort, quicksort.
    • Searching Algorithms: Linear search and binary search.

    13. Error Handling

    • Error Handling: Using errno, perror, and strerror for error reporting.
    • Setjmp and Longjmp: Non-local jumps for error handling.

    14. Modular Programming

    • Header Files: Creating and using header files.
    • Static and Extern: Understanding static and extern keywords.

    15. Concurrency

    • Multithreading: Basics of threading using POSIX threads (pthreads).
    • Synchronization: Using mutexes and semaphores to handle concurrency issues.

    16. Best Practices

    • Code Readability: Writing clean and maintainable code.
    • Documentation: Commenting and documenting your code effectively.
    • Version Control: Using Git for version control and collaboration.

    17. Project-Based Learning

    • Build Projects: Start with small projects like a calculator, to-do list, or simple game.
    • Incremental Complexity: Move on to more complex projects like a text editor, mini shell, or basic network server.

    18. Continuous Learning

    • Community Engagement: Join C programming communities on Stack Overflow, Reddit, or Discord.
    • Stay Updated: Follow C-related blogs, forums, and news.
    • Advanced Resources: Read advanced books like “The C Programming Language” by Kernighan and Ritchie, and “Expert C Programming: Deep C Secrets” by Peter van der Linden.

    By following this outline, you’ll build a solid foundation in C and progressively advance your skills through practical application and continuous learning.