LAB 2 Introduction to Algorithms and Programming Exercise

LAB 2 Introduction to Algorithms and Programming

Exercise 1: Write a C++ program that calculate the area of the circle

//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); }

Exercise 2: Write a C++ program that calculate the area of the rectangle

//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);

Exercise 3: Write a C++ program that convert the temperature from Fahrenheit to Celsius

//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); }

Exercise 4: Write a C++ program that convert the temperature from Celsius to Fahrenheit

//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) + 32. 0; cout<<"The Fahrenheit value is"<<f<<endl; return(0); }
- Slides: 9