Vous êtes sur la page 1sur 6

Lab Task # 1

Algorithm and Computing


Submitted by: Ns Muhammad Moiz Subhan Registeration no. 135 ME - 32 Syndicate A. Submitted to: Mam Saeeda Bibi

1. Objectives: The purpose of our 1st algorithm and computing lab class was to learn basic concept of performing arithmetic operations by first declaring a variable and then generating an output by giving input of any number we want 2. Lab task performed: i. Writing a program that takes two integers as input and gives their product as output of the program. Source Code: //Multiplication operation #include <iostream.h> int main() { int num1,num2,x; cout<<"Enter first number = "; cin>>num1; cout<<"Enter second number = "; cin>>num2; x=num1 * num2;

cout<<"\nThe product of these two numbers is "<<x<<endl; return 0; }

Output:

ii.

Writing a program that takes two integers as input and gives their remainder as output of the program. Source code:
#include <iostream.h> int main() { int num1,num2,x; cout<<"Enter first number = "; cin>>num1; cout<<"Enter second number = "; cin>>num2; x=num1 % num2; cout<<"\nThe remainder of 1st/2nd number is "<<x<<endl; return 0; }

Output:

iii.

Write a program that takes two integers as input and give their quotient as output of the program.

Source Code:

#include <iostream.h> int main() { int num1,num2,x; cout<<"Enter first number = "; cin>>num1; cout<<"Enter second number = "; cin>>num2; x=num1 / num2; cout<<"\nThe quotient of 1st/2nd number is "<<x<<endl; return 0; }

Output:

iv.

Writing a program that generates the following output: 10 20 19

Source code: #include <iostream.h> using namespace std; int main() { int num1=10,num2=20,x=19; cout<<num1<<"\n"<<num2<<"\n"<<x<<endl; return 0; }

Output:

v.

Write a program to reverse a number given by the user. Input should be given by the user Output should be displayed in proper format. Programs must be commented. Variable names must be chosen according to the requirements.

Source code: //Reversing of the numer of order 5


#include <iostream> using namespace std; int main() { int x,a,b,c,d,e,f; cout<<"Enter Five Digit Number!"<<endl;

cin>>x; a=x%10;//assigning variables x/=10; b=x%10; x/=10; c=x%10; x/=10; d=x%10; x/=10; e=x%10; f=a*10000+b*1000+c*100+d*10+e; cout<<"The reversed number is = "<<f<<endl;//result return 0; } OUTPUT:

Conclusion:
In my first lab, I learned how to define a variable and how to perform arithmetic operations.

Vous aimerez peut-être aussi