Uploaded by Akalu Kebede

lab 1

advertisement
Wachemo University
College of Engineering and Technology
Introduction to Computer Programming (Pre-Eng. Section. B)
Lab-01
1. Write a program in C++ to print welcome
text on a separate line.
#include <iostream>
sum=a+b;
cout << " The sum of a and b is : "<<
sum<<"\n\n";
return 0;
using namespace std;
int main ()
}
{
4. Write a C++ program to display the
operation of increment and decrement.
cout << "wel come to Engineering";
❖ Increment…
return 0;
#include <iostream>
}
2. Write a program in C++ to print the sum of
two numbers.
#include <iostream>
using namespace std;
int main ()
{
using namespace std;
int num = 7;
int main ()
cout << "\n\n Display the increment:\n";
num++;
{
cout <<" The number is : " << num << endl;
cout << " The sum of 9 and 3 is : "<< 9+3;
}
}
❖ Decrement…
3. Write a program in C++ to print the sum of
two numbers using variables.
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
int main ()
int main()
{
{
int num = 7;
cout << "\n\n Print the sum of two numbers :\n";
cout << "\n\n Display the Decrement:\n";
int a,b,sum;
a=2,b=3;
num++;
cout <<" The number is : " << num << endl;
}
cin>>width;
5. Write a C++ program to add two numbers
and accept them from the keyboard.
area=(length*width);
#include <iostream>
cout<<" The area of the rectangle is : "<<
area << endl;
cout << endl;
using namespace std;
return 0;
int main()
}
{
int num1, num2, sum;
7. Write a C++ program to compute the total
and average of four numbers.
cout << "\n Sum of two numbers :\n";
#include <iostream>
cout << " Input 1st number : ";
using namespace std;
cin >> num1 ;
int main()
cout << " Input 2nd number : ";
{
cin >> num2;
float n1,n2,n3,n4,tot,avrg;
sum = num1 + num2;
cout <<" The sum of the numbers is : "
<< sum << endl;
cout << endl;
return 0;
}
6. Write a C++ program to find the Area.
#include <iostream>
using namespace std;
cout << "\n\n Compute the total and average of
four numbers :\n";
cout<<" Input 1st two numbers (separated
by space) : ";
cin>> n1 >> n2;
cout<<" Input last two numbers (separated
by space) : ";
cin>> n3 >> n4;
tot=n1+n2+n3+n4;
avrg=tot/4;
int main()
{
int width, length, area;
cout << "\n\n Find the Area a Rectangle :\n";
cout<<" The total of four numbers is : "<< tot <<
endl;
cout<<" The average of four numbers is : "<<
avrg << endl;
cout<<" Input the length of the rectangle : ";
cout << endl;
cin>>length;
cout<<" Input the width of the rectangle : ";
return 0;
}
Download