Computer Assignment 18-09-23 1) Swapping 2 Numbers
Computer Assignment 18-09-23 1) Swapping 2 Numbers
1) Swapping 2 numbers
#include<stdio.h>
int main(){
int a,b;
printf("enter the 2 number to be swapped");
scanf("%d %d",&a,&b);
printf("\nthe 2 numbers before swapping a=%d and b=%d",a,b);
a = a+b;
b = a-b;
a = a-b;
printf("\nthe 2 numbers after swapping a=%d and b=%d",a,b);
return 0;
}
Output:
#include<stdio.h>
int main(){
char c;
printf("enter the charcter to be used ");
scanf("%c",&c);
printf("\ndecimal=%d",c);
printf("\noctal=%o",c);
printf("\nhexadecimal=%x",c);
return 0;
}
Output:
3. finding the third angle in a triangle
#include<stdio.h>
int main(){
int a,b,c;
printf("enter the angles of the trangle");
scanf("%d %d",&a,&b);
c = 180-a-b;
printf("\nthe value of the third side of the trisngle is %d",c);
return 0;
}
Output:
4. square root
#include<stdio.h>
#include<math.h>
int main(){
float num,s1,s2;
printf("enter the number");
scanf("%f",&num);
s1 = sqrt(num);
s2 = pow(num,0.5);
printf("\nthe square root of the number with sqrt function is %f",s1);
printf("\nthe square root of the number wthout sqrt function is
%f",s2);
return 0;
}
Output :
#include<stdio.h>
#include<math.h>
int main(){
float a,b,theta,area;
printf("enter the 2 sides and the angle of the triangle in radians");
scanf("%f %f %f",&a,&b,&theta);
area = (a*b*sin(theta))/2;
printf("the are of the triangle is %f",area);
return 0;
}
rem=a%10;
a=a/10;
b+=rem*1000;
rem=a%10;
a=a/10;
b+=rem*100;
rem=a%10;
a=a/10;
b+=rem*10;
rem=a%10;
a=a/10;
b+=rem;