Tuesday 3 July 2012

Basic C Programming005

The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area and circumference of the circle.

#include <stdio.h>
#include <conio.h>
void main ( )
{
        int          l, b, r, area1, peri;
        float       area2, circum, p=3.14;
        clrscr ( );
                      
        printf ("\n Enter the length breadth of Rectangle : -"); scanf ("%d %d",&l, &b);
        printf ("\n Enter the radius of Circle : -"); scanf ("%d",&r);   
                                    
        area1 = l * b;
        peri = 2 * ( l + b );
        area2 = p * r * r;
        circum = 2 * p * r;
                                     
        printf ("\n Area of Rectangle : - %d", area1);
        printf ("\n Perimeter of Rectangle : - %d", peri);
        printf ("\n Area of Circle : - %f", area2);
        printf ("\n Circumference of Circle : - %f", circum);
        getch ( );
}


Click here to contact us

Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        int       p, q, r;
        clrscr ( );
             
        printf ("\n Enter the number at location C : -"); scanf ("%d",&p);
        printf ("\n Enter the number at location D : -"); scanf ("%d",&q);
                 
        r = p;
        p = q;
        q = r;
                     
        printf ("\n New number at location C : - %d", p);
        printf ("\n New number at location D : - %d", q);
        getch ( );
}

Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...