c Pgms for Ds Lab Manual

download c Pgms for Ds Lab Manual

of 6

Transcript of c Pgms for Ds Lab Manual

  • 8/16/2019 c Pgms for Ds Lab Manual

    1/6

  • 8/16/2019 c Pgms for Ds Lab Manual

    2/6

    C program to calculate Electricit bill

    Aim:

    Write a C program to calculate )lectricit, bill or the given customer.

    Algorithm:

    Step1: Start

    Step 2: )nter Customer name

    Step 3: Read no. o units

    Step $: Calculate

    i !unit-"1#

    amount"units/$0

    else i !units1 units-"3#

    amount"units/$.'0

    else i !units3 units-"'#

    amount"units/$.'0

    else

    amount"units/'0

    Step ': %rint customer name and amount

    Step (: Stop

    Sample Input and Output:

    )nter Customer name and number o units

    4ohn 2'

  • 8/16/2019 c Pgms for Ds Lab Manual

    3/6

    Electricit !ill: 

     5ame: 4ohn

    6mount: Rs.112'

    Result:

    *hus the program has been e+ecuted successull,.

    C program to check the number is positive"negative odd or even #using $ested if%

    Aim:

    Write a C program to check whether the given number is positive7negative odd or even.

    Algorithm:

    Step 1: Start

    Step 2: Read a number 

    Step 3: 8!a# then

    Step $: 8!a92""# then

    Step ': %rint the given number is positive even

    Step (: )lse %rint the given number is positive odd

    Step: )lse

    Step : 8!a92""# then

    Step ;: %rint the given number is negative even

    Step1: )lse %rint the given number is negative odd

    Step11: Stop

  • 8/16/2019 c Pgms for Ds Lab Manual

    4/6

    Sample input and output:

    )nter a number 

    1'

    *he given number is positive odd

    Result:

    *hus the program has been e+ecuted successull,.

    C program to convert Seconds into &'(inutes )'*ours +',as #using switch%

    Aim:

    Write a C program to convert Seconds into 1.a,s

    Algorithm:

    Step1: Start

    Step 2: Read no. o seconds

    Step 3: %rint Seconds into

    1.

  • 8/16/2019 c Pgms for Ds Lab Manual

    5/6

     break0

    case 2:

    hrs " seconds 7 !(/(#0

     print!@hours:9dABhrs#0 break0

    case 3:da,s " seconds 7 !2$/(/(#0

     print!@da,s:9dABda,s#0 break0

    deault: print pls tr, again

    Step (: Stop

    Sample Input and Output:

    )nter no. o seconds

    123$'

    Seconds into

    1.

  • 8/16/2019 c Pgms for Ds Lab Manual

    6/6

    Algorithm:

    Step1: Start

    Step 2: )nter a number 

    Step 3:

    rev"B t"n0

    while!t"#

      ?  rem"t910

      rev"rev/1Drem0

      t7"10

      E

    7/ Checking i number entered b, user and itFs reverse number is equal. /7

    i!rev""n#

     print!G9d is a palindrome.GBn#0

      else  print!G9d is not a palindrome.GBn#0 

    Step $: stop

    Sample input and output:

    )nter a number 

    121

    121 is palindrome

    Result:

    *hus the program has been e+ecuted successull,.