4th sem oopc programs in C
Ø Write the following programs in C language.
#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
Post a Comment