MORE BASIC PROGRAMS TO PRACTISE IN C

PROGRAM 1. If length and breadth of rectangle are entered through keyboard , write a program to find area and perimeter of rectangle

CODING-:
                   #include<stdio.h>
                   #include<conio.h>
                   void main()
                   {
                    clrscr();
                    float l,b,area,perimeter;
                    printf(“Enter length and breadth of triangle \n”);
                    scanf(“%f%f”,&l,&b);
                    area = l*b;
                    perimeter = 2*l+2*b;
                    printf(“Area of rectangle is %f\n”, area);
                    printf(” Perimeter of rectangle is %f\n”, perimeter);
                    getch();
                    }

PROGRAM 3. Similiarly write program to find area of triangle, circle.

PROGRAM 2. WAP to swap two numbers.

CODING-:
                     #Include<stdio.h>
                  #include<conio.h>
                  void main()
                     {
                      clrscr();
                      int n,m,temp=0;
                      printf(“Enter the values of n and m\n”);
                      scanf(“%d%d”,&n,&m);
                      printf(“Values of n and m before swapping is %d,%d\n”, n, m);
                      temp=n;
                      n=m;
                      m=temp;
                      printf(“values of n and m after swapping is %d,%d\n”, n, m);
                      getch();
                      }
 
 

How it worked ?

  1. Here we want to interchange two numbers . So first we have declared variables which values   we want to interchange , and a third variable which we will use to exchange values.
  2. First value of n and m are entered through keyboard through scanf().
  3. Now see the statement temp=n; , here we are assigning value of n in third variable  temp.
  4. Next n=m; , here value of m get assigned in n.
  5. Finally m=temp; , here we assign value of m to temp.
  6. Look at the following picture to understand properly.

                  

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started