Download presentation
Presentation is loading. Please wait.
1
Introduction to Algorithms and Programming
LAB 2 Introduction to Algorithms and Programming
2
Exercise 1: Write a C++ program that calculate the area of the circle
3
//calculate the area of a circle
#include<iostream> using namespace std; int main() { float r,area; cout<<"Enter the value for radius"<<endl; cin>>r; area=3.14*r*r; cout<<"Area of Circle is"<<area<<endl; return(0); }
4
Exercise 2: Write a C++ program that calculate the area of the rectangle
5
//calculate the area of the rectangle
#include<iostream> using namespace std; int main() { float len,wid,area; cout<<"Enter the value for length"<<endl; cin>>len; cout<<"Enter the value for width"<<endl; cin>>wid; area=len*wid; cout<<"Area of Rectangle is"<<area<<endl; return(0);
6
Exercise 3: Write a C++ program that convert the temperature from Fahrenheit to Celsius
7
//temperature from Fahrenheit to Celsius
#include<iostream> using namespace std; int main() { float c,f; cout<<"Enter the value for Fahrenheit"<<endl; cin>>f; c=(5.0/9.0)*(f-32.0); cout<<"The Celsius value is"<<c<<endl; return(0); }
8
Exercise 4: Write a C++ program that convert the temperature from Celsius to Fahrenheit
9
//temperature from Celsius to Fahrenheit
#include<iostream> using namespace std; int main() { float c,f; cout<<"Enter the value for Celsius"<<endl; cin>>c; f= c* (9.0/5.0) ; cout<<"The Fahrenheit value is"<<f<<endl; return(0); }
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.