Wednesday, May 13, 2009

Monday, March 9, 2009

turbo c sample problems

the new telephone company has the follwing rate structure for long distance calls:

a. any call started after 7:00PM (1900hrs) but before 8:00 (0800 hours) is discounted 40%
b. any call stared after 8:00 am (0800 hours) but before 7:00 (1900 hours) is charged full.
c. all calls are subjected to 6% tax
d. the regular rate for a call is P7.00 per minute.
e. Any call longer than 60 minutes receives a 17% discount on its cost (after any other discount is subtracted but beofre tax is added)


write a c program that takes the start time for a call based on a 24-hour clock and the lenght of the call in minutes. the gross cost (before any discounts or tax) should be printed followed by the net cost (after discounts is deducted and tax added).


========
c code
========
#include

void computeGrossAndNetBill(int tym, int min)

{
float gross, net, discount=0, tax;
gross = min * 7.00;
tax = gross * 0.06;
if (1900 < tym=""><=800) { discount = gross * 0.40; } if (min >= 60)
{
discount += (gross - discount) * 0.17; /*discount = discount +...*/
}
net = gross - discount + tax;
printf("\ gross bill: %.2f", gross);
printf("\n net bill: %.2f", net);



}

int main()

{
int time, minutes;
clrscr();
printf("\n Enter start time of call in 24 hour format: ");
scanf("%d", &time);
printf("\n Enter total duaration of call in minutes: ");
scanf("%d", &minutes);
computeGrossAndNetBill(time, minutes);
return 0;
}

turbo c sample problems

create an application that loops from 1 to 50 and prints out each value on a separate line, except for "Fizz" for every multiple of 3, "Buzz" for every multiple of 5 and "FizzBuzz" for every multiple of 3 and 5.

example

1
2
3 fizz
4
5 Buzz
6 fizz
7 .....
8
9
.
.
.

15 FizzBuzz



===========
c source code
===========

#include
void FizzBuzz(void)

{

int ctr;
clrscr();
for (ctr=1; ctr<=50;ctr++)

{

if (ctr%3)
{
printf("\n%d ", ctr);
}
else
{
printf("\n%d Fizz",ctr);
}


if (ctr%5)
{

}
else
{
printf("Buzz");
}

delay(9999999999);

}








}


int main()

{

getch();
FizzBuzz();
return 0;

}

Wednesday, February 4, 2009

C programs

Function and Parameter Declarations
sample problems

#include

float addition(double num1, double num2);
float subtraction(double num1, double num2);
float multiplication(double num1, double num2);
float division(double num1, double num2);
float modulo(int num1, int num2);


main()

{

double num1, num2;
clrscr();
printf("\n Enter first number: ");
scanf("%lf", &num1);
printf("\n Enter second number: ");
scanf("%lf", &num2);
printf("\n The sum of %.2lf and %.2lf is equal to %.2lf", num1, num2, addition(num1, num2));
printf("\n The difference of %.2lf and %.2lf is equal to %.2lf", num1, num2, subtraction(num1, num2));
printf("\n The product of %.2lf and %.2lf is equal to %.2lf", num1, num2, multiplication(num1, num2));
printf("\n The quotient of %.2lf and %.2lf is equal to %.2lf", num1, num2, division(num1, num2));
printf("\n The modulo of %.2lf and %.2lf is %.2lf", num1, num2, modulo(num1, num2));
getch();
}

float addition(double num1, double num2)

{

int sum;
sum=num1+num2;
return sum;
}

float subtraction(double num1, double num2)

{

int difference;
difference=num1-num2;
return difference;

}

float multiplication(double num1, double num2)

{

int product;
product=num1*num2;
return product;

}


float division(double num1, double num2)

{
int quotient;
quotient=num1/num2;
return quotient;

}

float modulo(int num1, int num2)

{

long modu;
modu=num1%num2;
return modu;

}

shorter version------------------

#include

float addition(double num1, double num2)

{

return (num1+num2);

}

float subtraction(double num1, double num2)

{

return (num1-num2);

}

float multiplication(double num1, double num2)

{

return (num1*num2);

}


float division(double num1, double num2)

{

return (num1/num2);

}

float modulo(int num1, int num2)

{

return (num1%num2);
}

main()

{

double num1, num2;
clrscr();
printf("\n Enter first number: ");
scanf("%lf", &num1);
printf("\n Enter second number: ");
scanf("%lf", &num2);
printf("\n The sum of %.2lf and %.2lf is equal to %.2lf", num1, num2, addition(num1, num2));
printf("\n The difference of %.2lf and %.2lf is equal to %.2lf", num1, num2, subtraction(num1, num2));
printf("\n The product of %.2lf and %.2lf is equal to %.2lf", num1, num2, multiplication(num1, num2));
printf("\n The quotient of %.2lf and %.2lf is equal to %.2lf", num1, num2, division(num1, num2));
printf("\n The modulo of %.2lf and %.2lf is %.2lf", num1, num2, modulo(num1, num2));
getch();
}