TYBCOM

C PROGRAMMIMG –1

1. Write a program to compute the area and perimeter of a rectangle. Test the same with

the rectangle of width 3 inches and a height of 5 inches. (a=w*h , p=2*(b+h))

2. Write a program that converts Centigrade to Fahrenheit. Given F=9.0/5.0 *C + 32.

3. Write a program to calculate volume of a sphere. Given V= 4.0/3.0*22.0/7.0*r^3

4. Write a program to add 8% sales tax to a given amount.

5. A C program contains the following statements.

# include<stdio.h>

void main()

int x,y,u=15; float z;

Write a printf function for each of the following algebraic expression.

a) 2*y-z b) x/y – y/z + u c) x+4y d) sqrt(z-y) e) x+y+z

f) sqrt(+z) with minimum filed width 10 characters. g) 2xy-5z with minimum 2 decimal places

where as minimum width of 12 characters. h) x^2+y^2.

6. A C program contains the following variable declared.

int x=6782, y= - 12312, z= - 45678;

long ix= 987654321;

signed sx= -3333;

unsigned ux= 444;

Give the output resulting from each of the following printf() statement.

a)  printf(“\n%d,%d,%d”,x,y,z);

b)  printf(“\n %4d %4d\n\n %+8d %-8d”,x,y,x,y);

c)  printf(“\n %+-4ld %0ld\n\n%11ld %+11ld %-11ld”,ix,ix,ix,ix,ix);

d)  printf(“\n %4d %8d”,ux,ux);

e)  printf(“\n %8d %08d \n%8d %0d”,sx,sx,sx,sx);

f)  printf(“\n +%15d %08d\n%15ld %08ld”,ux,ux,ix,ix);

7. A C program contains the following variable declaration.

Char b= ‘P’,p= ‘Q’, g= ‘R’

Show the output resulting from each of the following printf() statement.

a)  printf(“\n %c%c%c”,b,p,g);

b)  printf(“\n %2c%2c%2c”,b,p,g);

c)  printf(“\n %4c%4c%4c”,b,p,g”);

d)  printf(“\n b=%c p=%c g=%c”,b,p,g);

8. A C program contains the following variable declaration.

Float x=10452.4, y=1.2345, z=40;

Show the output resulting from each of the following printf() statement.

printf(“\n %f %f %f”,x,y,z);

a)  printf(“\n %2f %2f %2f”,x,y,z);

b)  printf(“\n %7f %7f %7f”,x,y,z);

c)  printf(“\n %7.2f %7.2f %7.2f”,x,y,z);

d)  printf(“\n %+7f %+7f %+7f”,x,y,z);

e)  printf(“\n %-7f %-7f %-7f”,x,y,z);

f)  printf(“\n %07f %07f %07f”,x,y,z);