4th sem oopc programs in C


Ø Write the following programs in C language.

1.Write a program to find area of a circle.

#include<stdio.h>
#include<conio.h>
#define PI 3.14
int main(){
 float r,ans;
 printf(" Enter the radius os circule r=");
 scanf("%f",&r);
 ans=PI*r*r;
 printf("\n Radius of the circle is %.2f ",ans);
 return 0;
}


2.      Write a program for sum of two numbers.

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

int main(){
    int a,b,c;
    printf("\n Enter the value of A=");
    scanf("%d",&a);
    printf("\n Enter the value of B=");
    scanf("%d",&b);
    c=a+b;
    printf("\n Sum of two number is %d \n",c);

    return 0;
}



3.      Write a program to swap two numbers using third variable.

#include<stdio.h>
#include<conio.h>
int main(){
  int a,b,temp;
  printf("Enter two number. \n");
  scanf("%d %d",&a,&b);
  printf("before\n  A=%d \n  B=%d \n",a,b);
  temp=a;
  a=b;
  b=temp;
  printf("After Swap\n A=%d \n B=%d \n",a,b);
  return 0;
}


4.      Write a program to swap two numbers without using third variables.


#include<stdio.h>
#include<conio.h>
int main(){
  int a,b,temp;
  printf("Enter two number. \n");
  scanf("%d %d",&a,&b);
  printf("before\n  A=%d \n  B=%d \n",a,b);
  a=a+b;
  b=a-b;
  a=a-b;
  printf("After Swap\n A=%d \n B=%d \n",a,b);
  return 0;
}

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab 3

SQL Lab1: Create a Database Table for DayCare