C Practicals Ishrat

download C Practicals Ishrat

of 27

Transcript of C Practicals Ishrat

  • 8/8/2019 C Practicals Ishrat

    1/25

    1

    PROJECT FILE

    C-LANGUAGEPRACTICAL(S)

    IIsshhrraattD/oMuhammad Mubeenul Haq

    First Year DAE (CIT)

    IIsshhrraatt

  • 8/8/2019 C Practicals Ishrat

    2/25

    2

    DAE (CIT)

    First Year

    INFORMATION

    TECHNOLOGY

    Institute:

    Govt Monotechnic Institute,

    Orangi 7, Karachi

  • 8/8/2019 C Practicals Ishrat

    3/25

    3

    Index

    S# P

    c

    c

    l Objec

    ve

    e S

    gn

    0

    o le

    n

    u

    bo-

    P

    og

    mmng env

    onmen

    .

    02

    o p

    n

    ou

    n

    me on sc

    een

    03

    o s

    udy

    h

    ee d

    ypes of

    l

    ngu

    ge:

    04

    o s

    udy

    he use of fo

    m

    spec

    f

    e

    s:

    05

    o s

    udy

    he use of fo

    m

    specf

    e

    s by usng

    v

    ble:

    06

    o m

    ke m

    ks shee

    of ex

    m:

    07

    o decl

    e mul

    ple v

    bles

    nd show

    hem on sc

    een:

    08

    o

    ke

    ge of

    use

    n ye

    s

    snpu

    nd fnd ou

    he numbe

    of

    d

    ys :

    09 W

    e

    p

    og

    m

    h

    kesnpu

    f

    om use

    nd dspl

    y on sc

    een.

    0

    o f

    nd ou

    he pe

    cen

    ge of m

    ks

    n ex

    m by use

    npu

    .

    (a) W

    e

    p

    og

    m whch uses f

    eld spec

    f

    e

    s.

    (b) W

    e

    p

    og

    m whch uses f

    eld spec

    f

    e

    s.

    (c ) W

    e

    p

    og

    m whch uses f

    eld spec

    f

    e

    s.

    2

    W

    e

    p

    og

    m wh

    ch coun

    s

    he

    o

    l numbe

    of ch

    c

    e

    s

    yped.

    3

    W

    e

    p

    og

    m whch

    kes use

    npu

    s ch

    c

    e

    s

    nd fo

    ch

    c

    e

    Y

    d

    spl

    ys

    mess

    ge.

    14 Mod fy

    he p

    og

    m of l

    b#13 by usng

    f-else cond

    on.

    15 W

    e

    p

    og

    m

    o

    vod unnecess

    y

    epe

    on by us

    ng fo

    loop.

    16

    W

    e

    p

    og

    m

    h

    uses fo

    loop

    nd

    func

    on

    o p

    n

    ex

    n

    box.

    17

    W

    e

    p

    og

    m whch c

    n c

    lcul

    e mn

    mum

    nd m

    xmum of

    he

    wo numbe

    s by p

    ssng p

    me

    e

    sn func

    ons.

    18 W

    e

    p

    og

    m whch c

    n c

    lcul

    e f

    c

    o

    l of

    gven numbe

    .

    19 W

    e

    p

    og

    m whch shows

    dffe

    en

    loc

    ons of

    n

    y.

    20 W

    e

    p

    og

    m wh

    ch shows

    d

    ffe

    en

    loc

    ons of

    n

    y.

  • 8/8/2019 C Practicals Ishrat

    4/25

    4

    Lab 1

    OBJECTIVE:T

    earn T r

    C r

    gramming en

    ir

    nment.

    THEORY:C Progr

    m consists of functions the m

    in

    function is the one which controls is p

    ssed when the is executed.

    CODE:

    #include //header file#include //header file

    void main(void) //main function

    {

    clrscr(); //clear scree

    printf("Hello World");

    getche(); //get character with echo wait

    }

    PRACTICAL OUTPUT:

    Hello World

  • 8/8/2019 C Practicals Ishrat

    5/25

    5

    Lab 2

    OBJECTIVE:T

    rint

    r name

    n screen

    THEORY:The printf function is

    !vers

    !tile

    !nd powerful function.

    Syntax:printf

    "

    some string #

    ;

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    printf("Ishrat);

    getche();

    }

    PRACTICAL OUTPUT:

    Ishr t

  • 8/8/2019 C Practicals Ishrat

    6/25

  • 8/8/2019 C Practicals Ishrat

    7/25

    7

    Lab 4

    OBJECTIVE:

    T0

    st 1 dy t 2 e 1 se0

    3

    3

    0

    rmat s 4 eci3

    iers:

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    printf("This is number %d",20);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    8/25

    8

    Lab 5

    OBJECTIVE:

    T5

    st 6 dy t 7 e 6 se5

    8

    8

    5

    rmat s 9 eci8

    iers @ y 6 sing aA

    aria @ B e:

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    int a; // variable declaration

    a=2;

    printf("Value of a is %d",a); //variable call

    printf("\nMy name is %s,Ishrat);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    9/25

    9

    Lab 6

    OBJECTIVE:

    TC

    make marks s D eetC

    E

    exam:

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();int math,eng,urdu,islamiat,science; //declaration of variables

    math=70;

    eng=60;

    urdu=20;

    islamiat=80;

    science=90;

    printf("Math=%d\nEnglish=%d\nUrdu=%d\nIslamiat=%d\nScience=%d\n",math,eng,

    urdu,islamiat,science);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    10/25

    1F

    Lab 7

    OBJECTIVE:T

    G

    dec H are m I H ti P H eQ

    aria R H es and s SG T

    t S emG

    n screen:

    CODE:

    #include

    #include

    void main(void)

    {clrscr();

    int num1, num2;

    char option1, option2;

    float point1,point2;

    num1=10;

    num2=20;

    option1='y';

    option2='n';

    point1=20.2;

    point2=30.2;

    printf("Option 1=%c\nNumber 1= %d\nPoint 1=%f",option1,num1,point1);

    printf("\nOption 2=%c\nNumber 2= %d\nPoint 2=%f",option2,num2,point2);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    11/25

    11

    Lab 8

    OBJECTIVE:

    TU

    take ageU

    V

    a W ser in years as in X W t andV

    indU

    W t t Y e n W m erU

    V

    days :

    CODE:

    #include

    #include

    void main(void)

    {clrscr();

    float years, days;

    printf("Please type your age in years:");

    scanf("%f",&years);

    days=years*365;

    printf("You are %.2f days old!\n",days);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    12/25

    12

    Lab 9

    OBJECTIVE:

    Write a a rb

    gram t c at takes in a d te

    rb

    m d ser and dis a f ayb

    n screen.

    CODE:

    #include

    #include

    void main(void)

    {clrscr();

    int age;

    float height;

    char gender;

    printf("Type your age, gender(m/f), and height.\n");

    scanf("%d %c %f",&age,&gender,&height);

    printf("You are %d years old, your height is %f feet, your gender is

    %c",age,height,gender);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    13/25

    13

    Lab 10

    OBJECTIVE:

    Tg

    h

    indg

    i t t p e q ercentageg

    h

    marks in exam r y i ser in q i t.

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    int cp,as,isl,math,phy;float sum, perc;

    printf("Enter marks of Computer Programming.\n");

    scanf("%d",&cp);

    printf("Enter marks of Application Software.\n");

    scanf("%d",&as);

    printf("Enter marks of Islamiat.\n");

    scanf("%d",&isl);

    printf("Enter marks of Mathematics.\n");

    scanf("%d",&math);

    printf("Enter marks of Physics.\n");

    scanf("%d",&phy);

    sum=cp+as+isl+math+phy;perc=sum*100/500;

    printf("Your percentage is %.2f",perc);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    14/25

    14

    Lab 11(a)

    OBJECTIVE:

    Write a s rt

    gramu

    v ic v w sesx

    ie y d s s ecix

    iers.

    CODE:#include

    #include

    void main(void)

    {

    clrscr();

    float event=27.25;

    printf("event %.2f\n",event);

    printf("event %.1f\n",event);

    printf("event %f",event);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    15/25

    15

    Lab 11(b)

    OBJECTIVE:

    Write a r

    gram

    ic ses

    ie d s eci

    iers.

    CODE:

    #include

    #include

    void main(void)

    {clrscr();

    float event=27.25;

    printf("%8.1f %8.1f %8.1f\n",3.0,12.5,523.3);

    printf("%8.1f %8.1f %8.1f\n",300.0,1200.5,5300.3);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    16/25

    16

    Lab 11(c)

    OBJECTIVE:

    Write a r

    gram

    ic ses

    ie d s eci

    iers.

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    float event=27.25;

    printf("%-8.1f %-8.1f %-8.1f\n",3.0,12.5,523.3);

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    17/25

  • 8/8/2019 C Practicals Ishrat

    18/25

    18

    Lab 13

    OBJECTIVE:

    Write a r

    gram

    ic takes j ser in j t as c aracters andk

    r c aracter Y it dis l ays a

    message.

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    char ch;

    printf("Type any character.\n");

    ch=getche();

    if(ch=='Y')

    {

    printf("\nYou typed Y.\n");

    printf("You did it\n");

    }

    printf("\nTry again :-( please.");

    getche();

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    19/25

  • 8/8/2019 C Practicals Ishrat

    20/25

    20

    Lab 15

    OBJECTIVE:

    Write a rogram to a

    oid nnecessary re etition y sing for z oop.CODE:#include

    #include

    void main(void)

    {

    clrscr();

    int i;

    for(i=0;i

  • 8/8/2019 C Practicals Ishrat

    21/25

    21

    Lab 16

    OBJECTIVE:

    Write a program t { at | ses for } oop and a function toprint a text in a ~ ox.

    CODE:

    #include

    #include

    void line(void);

    // Function prototype is defined here and semicolon at end

    void main(void)

    {clrscr();

    line(); //Function is called

    printf("\xDBIntro to Programming\xDB\n");

    // \xDB is the ASCII code for a box

    line();

    getche();

    }

    void line(void) //Function definition

    {

    int i;

    for(i=1;i

  • 8/8/2019 C Practicals Ishrat

    22/25

    22

    Lab 17

    OBJECTIVE:

    Write a program

    ic

    can ca

    culate minimum and maximum oft

    e t

    o num

    ers

    y

    passing parameters in functions.

    CODE:

    #include

    #include

    double minimum(double a, double b);

    double maximum(double a,double b);

    void main(void)

    {

    clrscr();

    printf("Minimum of 11 and 23 is = %f\n",minimum(11, 23));

    printf("Maximum of 10 and 20 is = %f",maximum(01, 20));

    getche();

    }

    double minimum(double a, double b)

    {

    return a < b ? a : b;

    }

    double maximum(double a,double b)

    {

    return a > b ? a : b;

    }

    PRACTICAL OUTPUT:

  • 8/8/2019 C Practicals Ishrat

    23/25

    23

    Lab 18

    OBJECTIVE:

    Write a program

    ic can calculate factorialofa gi

    en num er.

    CODE:

    #include

    #include

    int factorial(unsigned int number)

    {

    if(number

  • 8/8/2019 C Practicals Ishrat

    24/25

    24

    Lab 19

    OBJECTIVE:

    Write a program

    ic s ows at different locations ofan array.

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    short age[4]; // array declarationage[0]=23; //array elemets index wise assignment

    age[1]=34;

    age[2]=65;

    age[3]=74;

    //printing array elements

    for(int i=0; i

  • 8/8/2019 C Practicals Ishrat

    25/25

    25

    Lab 20

    OBJECTIVE:

    Write a program which shows at different locations ofan array.

    CODE:

    #include

    #include

    void main(void)

    {

    clrscr();

    short mat[3][3],i,j;

    for(i = 0 ; i < 3 ; i++)

    for(j = 0 ; j < 3 ; j++)

    {

    mat[i][j] = i*10 + j;

    }

    printf(" Initialized data to: ");

    for(i = 0 ; i < 3 ; i++)

    {

    printf("\n");

    for(j = 0 ; j < 3 ; j++)

    {

    printf("%5.2d", mat[i][j]);}

    }

    getche();

    }

    PRACTICAL OUTPUT: