Tutorial – 2 (15.01.2007)

Program 1.    Write a C program that accepts three numbers and prints the largest one.

Open emacs editor :

$ emacs program1.c &

 

Type program1.c :

 

/*************************************************

*                                              Section : 2                                  *

* M/c No. : 11,                                    Roll No. : 06AE3011,   *

*                                  Name : G S VIMAL,                               *

*                                  Assignment No. : 01,                               *

*           Description : Program to print largest                           *

*                                from three real number                                *                 

***************************************************/  

#include<stdio.h>

int main()

{

  float a,b,c;

 

  printf("\nEnter three real number's :\n");

  scanf("%f%f%f",&a,&b,&c);

 

  if(a>=b)

    if(a>=c)  printf("\n%f is largest\n",a);

    else  printf("\n%f is largest\n",c);

 

  else  if(b>=c)  printf("%f is largest\n",b);

        else   printf("%f is largest\n",c);

 

  return 0;

}

 

Compile program1.c  :

$ cc program1.c

 

Run program1.c  :

$ ./a.out

Enter three real number's :

1.3

55.67

55.33

55.669998 is largest

Program 2.   Write  a C program to evaluate the following functions

 

               x2 + 9              if x < 0

   f(x) =  x4 + 3x2 + 7       if 0 £ x < 20

               12x + 7            otherwise

 

Open emacs editor :

$ emacs program2.c &

 

Type program2.c :

 

/*************************************************

*                                              Section : 2                                  *

* M/c No. : 11,                                    Roll No. : 06AE3011,   *

*                                  Name : G S VIMAL,                               *

*                                  Assignment No. : 02,                               *

*           Description : Program to compute the                          *

*                                 value of a given function                             *                 

***************************************************/  

#include<stdio.h>

int main()

{

  float x, fx, temp;

 

  printf("\nEnter the value of x : ");

  scanf("%f",&x);

 

  if(x<0.0)  fx = x * x + 9.0;

  else  if(x<20.0)

          {

              temp = x * x;

              fx = temp * (temp + 3.0)+ 7.0;

          }

        else  fx = 12.0 * x + 7.0;

  printf("\n f(%f) = %f\n",x,fx);

 

  return 0;

}

 

 

Compile program2.c  :

$ cc program1.c

 

Run program2.c  :

$ ./a.out

Enter the value of x : -1.0

 f(-1.000000) = 10.000000

$ ./a.out

Enter the value of x : 0.0

 f(0.000000) = 7.000000

$ ./a.out

Enter the value of x : 20.0

 

 f(20.000000) = 247.000000

$ ./a.out

Enter the value of x : -0.99

 

 f(-0.990000) = 9.980100

$ ./a.out

Enter the value of x : 0.99

 

 f(0.990000) = 10.900896

$ ./a.out

Enter the value of x : 19.99

 

 f(19.990000) = 160886.031250

$ ./a.out

Enter the value of x : 20.001

 

 f(20.000999) = 247.011993

 

 

 

 

 

 

 

 

 

 

 

LAB ASSIGNMENT (15.01.2007)

Assignment 1.   Write a C program that accept distance (in cm.) as integer and print it in kilometer, meter and centimeter.

Example :

 Input :   distance = 254780

Output : 2 kilometer, 547 meter and 80 centimeter.      

Assignment 2.   a)  Write a C program to evaluate the income tax of a person.

                        Input:     Income of a person (type unsigned int).

                      Output:  Income Tax to be paid (also of type unsigned int).

Let I be the income and T be the tax on total income.

1.  If I <= Rs. 1,00, 000, T is zero.

2.  If Rs. 1, 00, 001 <=  I  <= Rs. 1,50,000, T is 10% of (I – 1,00, 000).

3.  If Rs. 1, 50, 001  <= I <= Rs. 2, 50, 000, T is 20% of (I – 1, 50, 000) plus Rs. 5000.

4.  If Rs. 2, 50, 001 <= I, T is 30% of (I – 2, 50, 000) plus Rs. 25000.

b)   Add in the above programme 2% of the tax on total income (T), as education cess to get   the final income tax. 

Report output for the following four data (income).

Income (Rs.)

75,000

1,30,000

2,20,000

3,40,000