0% found this document useful (0 votes)
15 views4 pages

Computer Assignment 18-09-23 1) Swapping 2 Numbers

Uploaded by

aadya sajankila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Computer Assignment 18-09-23 1) Swapping 2 Numbers

Uploaded by

aadya sajankila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer assignment 18-09-23

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:

2)read a character and writing its ascii value

#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 :

5.finding the area of triangle

#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;
}

6. reverse the number


#include<stdio.h>
int main(){
int a,b,rem;
printf("enter the 5 digit number");
scanf("%d",&a);
b=0;
rem=a%10;
a=a/10;
b+=rem*10000;

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;

printf("the number after reversing is %d",b);


return 0;
}
Output :

You might also like