Uploaded by Anik Ahsan

Takeaway Assignments - 1

advertisement
you recognize.
(a)
main()
printf("We1come t o t h e Wonderful World o f C o m p u t i n g ! \ n " ) ;
1
Takeaway
Basic Ct o Programs
(6) Assignments:
# d e f i n e MESSAGE "Welcome
t h e Wonderful World o f
Computing!\n"
main ( )
Practice to solve the following problems
using C:
{
•
printf(MESSAGE);
Write a C program with the following contents of your main function. Try to
1
understand how scanf/printf is working. Can you guess what is it calculating?
(c)
main()
f l o a t base, h e i g h t , area;
p r i n t f ("Base: " ) ;
scanf ( "%f
U , &base) ;
p r i n t f ( "Height: " ) ;
scanf ( ' % f
&height) ;
area = (base * h e i g h t ) / 2.;
p r i n t f ( " A r e a : % f ', a r e a ) ;
'I,
1
•
Write a C program with the following contents of your main function. Try to
understand how scanf is working. Particularly, pay attention to the “%0.2f” part in
CHAP. I ]
INTRODUCTORY CONCEPTS
the last two printf statements. Try removing “0.2” from that part and investigate
what happens when it is removes. Can you identify the difference?
{
f l o a t gross, t a x , n e t ;
p r i n t f ( "Gross s a l a r y : " ) ;
scanf %
("'fi
, &gross) ;
t a x = 0.14 * gross;
net = gross - tax;
p r i n t f ("Taxes w i t h h e l d : % . 2 f \ n " , t a x ) ;
p r i n t f ("Net salary: %.2f , net) ;
I'
I"
1
•
•
•
) input
i n t s mtwo
a l l enumbers
r ( i n t a, i from
n t b ) ;the user and print their addition and
Write a C program( eto
subtraction using printf.
main ( )
Write a C program to draw a circle using only *. Hint: it will be similar to the way you
have drawn a pyramid{ using * in your lab.
i n t a, b y min;
Write a C program to draw a rectangle using *.
p r i n t f ( ""Please e n t e r t h e f i r s t number:
scanf ("d" , &a) ;
p r i n t f ( " P l e a s e e n t e r t h e second number:
I")
;
I")
;
scanf ( "%d", &b) ;
min = s m a l l e r ( a , b ) ;
p r i n t f ( " \ n T h e s m a l l e r number i s : % d " , m i n ) ;
i n t s m a l l e r ( i n t a, i n t b )
{
i f ( a <= b )
return(a);
else
return(b);
1
U,
i n t s m a l l e r ( i n t a, i n t b ) ;
main ( )
{
i n t count, n, a, b y min;
Download