You are on page 1of 3

Department of Electrical Engineering

Roll # 11053122-073

Data Structure and Algorithm Lab


Subject Code:

(EE-286) Instructor: Engr. Arslan Arif Prepared by: Muhammad Ateeb Akmal Section:B

Program to exchange value of two variables:


#include<iostream.h> #include<conio.h> int main() { int a,b,c; cout<<"Enter a value of a="; cin>>a; cout<<"Enter value of b="; cin>>b; c=a; a=b; b=c; cout<<"Value of a after exchange a=" <<a<<endl; cout<<"Value of b after exchange b=" <<b; getch(); }

Program to show first 10 natural numbers:


#include<iostream.h> #include<conio.h> int main() { int a; for(a=1;a<=10;a++) cout<<a<<endl; getch(); }

Program to check the largest number:


#include<iostream.h> #include<conio.h> main() { int a,b,c,d; clrscr(); cout<<"enter first number = "; cin>>a; cout<<endl<<"enter second number = "; cin>>b; cout<<endl<<"enter third number = "; cin>>c; if(a>b) if(a>c) cout<<endl<<"largest num among three is = "<<a; else cout<<endl<<"largest num among three is = "<<c; else if(b>c) cout<<endl<<"largest num among three is = "<<b; else cout<<endl<<"largest num among three is = "<<c; getch(); return 0; }

You might also like