mca c lab file

download mca c lab file

of 22

Transcript of mca c lab file

  • 8/13/2019 mca c lab file

    1/22

    Ques. 1. A grocery shop decides to give its customers a discount 10% on the total purchases if itexceeds Rs. 1000. The quantity purchased and price per item is entered through the keyoard. !A" tocalculate the final sales ill.

    Ans. 1#include$stdio.h

    void main&'(float ap) dis)cal)ill*

    printf&+enter the actual price , +'*scanf&+%f+) -ap'*printf&+enter the discount , +'*scanf&+%f+)-dis'*

    cal &ap/dis100'*ill &apcal'*printf&+%f2n+)ill'*3

  • 8/13/2019 mca c lab file

    2/22

    output 1,

  • 8/13/2019 mca c lab file

    3/22

    Ques 4. The current year and the year of 5oining of any employee are taken as input from the keyoard.6f the numer of years of service is more than 7 then a onus of Rs. 4800 is given else nothingelse is done. The pay of an employee is calculated as under,a. 6f asic salary is less than Rs. 1800 then 9RA10% - :A;0% of asic.. 6f asic salary is greater than or equal to Rs. 1800 then 9RARs.800 - :A;onus is Rs %d+)onus'*3if&s$1800'(hra s/10100*da s /;0100*printf&+hra is ,%d+)hra'*printf&+da is ,%d+)da'*3else(hra 800*da s/;

  • 8/13/2019 mca c lab file

    4/22

    @utput 4 ,

  • 8/13/2019 mca c lab file

    5/22

    Ques 7. !A" to find the greatest of three numers using ifelse and conditional operators.Ans 7.#include$stdio.h

    void main&'(

    int a))c*

    printf&+=nter the value of first no. ,+'*scanf&+%d+)-a'*printf&+=nter the value of second no. ,+'*scanf&+%d+)-'*printf&+=nter the value of third no. , +'*scanf&+%d+)-c'*

    if&&a'--&ac''(printf&+first no. is greater+'*3else if&&c'--&a''(printf&+second no. is greater+'*3else(printf&+Third no. is greater+'*33

  • 8/13/2019 mca c lab file

    6/22

    @utput 7 ,

  • 8/13/2019 mca c lab file

    7/22

    Ques ,!A" to determine Bhether a given year is a leap year or not using -- and CC operators.Ans .#include$stdio.h

    void main&'(

    int a*printf&+=nter a year2n,+'*scanf&+%d+)-a'*

    if&&a%0--a%100D0'CCa%000'(printf&+this is a leap year +'*3else(printf&+this is not a leap year +'*3

    3

  • 8/13/2019 mca c lab file

    8/22

    @utput ,

  • 8/13/2019 mca c lab file

    9/22

    Ques 8, Earks of 8 su5ects are entered through the keyoard and division is allotted according to thefolloBing criteria,a. Freater than or equal to G0% 6 :ivision. >etBeen 80% and 8;% 66 :ivisionc. >etBeen 0% and ;% 666 :ivisiond. Hess than 0% Iail

    Ans 8.#include$stdio.h

    void main&'(

    int c)ppm)dm)fit)maths)tm*float per*printf&+=nter the c language marks ,+'*scanf&+%d+)-c'*printf&+=nter a ppm marks ,+'*scanf&+%d+)-ppm'*printf&+=nter the dm marks ,+'*scanf&+%d+)-dm'*printf&+=nter the fit marks ,+'*scanf&+%d+)-fit'*printf&+=nter the maths marks ,+'*scanf&+%d+)-maths'*

    tm c?ppm?dm?fit?maths*per tm8*

    if&perG0'(printf&+percentage is %f2n+) per'*printf&+2n6 :ivision+'*3else if&&per80'--&per$8;''(printf&+percentage is %f2n+) per'*printf&+2n 66 :ivision+'*3else if&&per0'--&per$;''(printf&+percentage is %f2n+) per'*printf&+2n 666 :ivision+'*3else(printf&+percentage is %f2n+) per'*printf&+@ooopsD Jorry you are fail2n+'*33

  • 8/13/2019 mca c lab file

    10/22

    @utput 8 ,

  • 8/13/2019 mca c lab file

    11/22

    Ques G, A character is entered through the keyoard* find Bhether it is a capital letter) small letter orspecial symol. The AJK66 values are given eloB for referencea. A L M G8;0. a L N ;O144c. 0 L ;

  • 8/13/2019 mca c lab file

    12/22

    @utput G ,

  • 8/13/2019 mca c lab file

    13/22

    Ques O, !A" to find out the sum of tBo numers Bithout using ? operator.Ans O.#include$stdio.h

    void main&'(

    int a) ) sum 0*

    printf&+=nter a first no.2n +'*scanf&+%d+)-a'*printf&+=nter a second no.2n +'*scanf&+%d+)-'*

    sum a?*printf&+sum is %d2n+) sum'*3

  • 8/13/2019 mca c lab file

    14/22

    @utput O ,

  • 8/13/2019 mca c lab file

    15/22

    Ques

  • 8/13/2019 mca c lab file

    16/22

    @utput

  • 8/13/2019 mca c lab file

    17/22

    .' Bith using else option.

    #include$stdio.h

    void main&'(

    int a*printf&+enter a no. +'*scanf&+%d+)-a'*

    if&a%40'(printf&+This is even numer2n+'*3else(printf&+This is odd numer2n+'*33

  • 8/13/2019 mca c lab file

    18/22

    @utput

  • 8/13/2019 mca c lab file

    19/22

    Ques ;, !A" to design a Jimple 6nterest Kalculator.Ans ;.#include$stdio.h

    void main&'(

    int i0)p)t*float r*

    printf&+=nter the principal value ,2n+'*scanf&+%d+)-p'*printf&+=nter the rate of interest ,2n+'*scanf&+%f+)-r'*printf&+=nter the time ,2n+'*scanf&+%d+)-t'*

    i &p/r/t'*printf&+Jimple interest is %d,2n+)i'*

    3

  • 8/13/2019 mca c lab file

    20/22

    @utput ; ,

  • 8/13/2019 mca c lab file

    21/22

    Ques 10, !rite a menu driven program for arithmetic calculator.Ans 10.#include$stdio.h

    void main&'(

    int a))ch)sum)mult)divide)sutract*

    do(printf&+select 1. for sum 2n+'*printf&+select 4. for multiply2n+'*printf&+select 7. for divide2n+'*printf&+select . for sutract2n+'*printf&+choose anyone+'*scanf&+%d+)-ch'*

    sBitch&ch'(

    case 1,printf&+=nter a first no.2n ,+'*scanf&+%d+)-a'*printf&+=nter a second no. 2n,+'*scanf&+%d+)-'*sum a?*printf&+sum is ,%d+)sum'*

    reak*case 4,

    printf&+=nter a first no.2n ,+'*scanf&+%d+)-a'*printf&+=nter a second no. 2n,+'*scanf&+%d+)-'*mult a/*printf&+multiply is ,%d+)mult'*

    reak*case 7,

    printf&+=nter a first no.2n ,+'*scanf&+%d+)-a'*printf&+=nter a second no. 2n,+'*scanf&+%d+)-'*divide a*printf&+:ivide is ,%d+)divide'*

    reak*case ,

    printf&+=nter a first no.2n ,+'*scanf&+%d+)-a'*printf&+=nter a second no. 2n,+'*scanf&+%d+)-'*sutract a*

  • 8/13/2019 mca c lab file

    22/22

    printf&+sutract is ,%d+)sutract'*default,printf&+you enter Brong choice+'*3

    3Bhile&a0'*

    3

    @utput 10 ,