Assignment 2
Assignment 2
#include <stdio.h>
int main() {
float radius, area;
return 0;
}
Output:
Enter the radius of the circle: 7
The area of the circle is 153.94
#include <stdio.h>
void main() {
/* Variable Declaration. */
float radius, perimeter, area;
Q3. write a program in c to convert temperature in Celsius to Fahrenheit by taking value entered by
user.
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
return 0;
}
Output:
Enter temperature in Celsius: 34
34.00 Celsius = 93.20 Fahrenheit
#include<stdio.h>
int main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
Output:
Enter first number: 11
Enter second number: 12
Q5. Write a program in C to swap two numbers using without a Third variable.
#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
Output:
Before swap a=10 b=20
After swap a=20 b=10
------------------------------------------------------OR-----------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a*b;//a=200 (10*20)
b=a/b;//b=10 (200/20)
a=a/b;//a=20 (200/10)
system("cls");
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}
Output:
Before swap a=10 b=20
After swap a=20 b=10