You are on page 1of 9

Q.1:Write a programme to calculate the area of a circle using function. //M.

NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> float circarea(int); inline float circarea(int radius) { return 3.14*radius*radius; } void main() { clrscr(); int r; cout<<"Enter Radius:"; cin>>r; cout<<"Area of Circle="<<circarea(r)<<endl; getch(); }

Q.2:Write a programme using function to raise a number n to a power p. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> double power(double,int); void main() { clrscr(); double n; int p; cout<<"Enter integer:"; cin>>n; cout<<"Enter power:"; cin>>p; power(n,p); cout<<"The number is:"<<power(n,p); getch(); } double power(double n,int p) { int i; double k; k=1; if(p>2) for(i=1;i<=p;i++) { k=k*n; } return k; if(p==2) return n*n; }

Q.3:Write a program that take two int arguments by reference and then sets the smaller of two numbers to 0. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> int zerosmaller(int&,int&); void main(){ clrscr(); int a,b; cout<<"Enter a number:"; cin>>a; cout<<"Enter 2nd number:"; cin>>b;s cout<<"Numbers are:"<<a<<" "<<b<<endl; zerosmaller(a,b); cout<<"Smaller number is:"<<zerosmaller(a,b); getch(); } int zerosmaller(int& x,int& y) { if(x<y) return x; else return y; }

Q.4: Write a program that takes two distance values as arguments and returns the larger one. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> int show(int,int); void main(){ clrscr(); int a,b; cout<<"Enter distence.1:"; cin>>a; cout<<"Enter distence.2:"; cin>>b; cout<<"The distences are:"<<a<<" "<<b<<endl; cout<<"Larger distences is:"<<show(a,b); getch(); } int show(int x,int y) { if(x>y) return x; else return y; }

Q.5: Write a program that takes three int values in hours, minutes and seconds as arguments and returns the equivalent time in seconds. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> int hms_to_secs(int,int,int); void main(){ clrscr(); int a,b,c; cout<<"Enter hours:";z cin>>a; cout<<"Enter minuts:"; cin>>b; cout<<"Enter seconds:"; cin>>c; cout<<"The time is:"<<a<<":"<<b<<":"<<c<<endl; cout<<"The time in seconds is:"<<hms_to_secs(a,b,c)<<"seconds"; getch(); }

int hms_to_secs(int x,int y,int z) { return (x*3600)+(y*60)+z; }

Q.6: Write a program that converts time from hh:mm:ss to seconds and vice versa. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> long time_to_secs(int,int,int); int secs_to_time(long); struct time { int h; int min; int sec; }; void main(){ clrscr(); time a; int h,min,sec; long x; cout<<"Enter hours:";

cin>>a.h; cout<<"Enter minutes:"; cin>>a.min; cout<<"Enter seconds:"; cin>>a.sec; cout<<"The time in hh:mm:ss formate is:"<<a.h<<":"<<a.min<<":"<<a.sec<<endl; x=time_to_secs(a.h,a.min,a.sec); cout<<"Time in seconds is:"<<x<<"seconds"<<endl; secs_to_time(x); cout<<"Time in hh:mm:ss format is:"<<a.h<<":"<<a.min<<":"<<a.sec; getch(); } long time_to_secs(int t,int u,int v) { return (t*3600)+(u*60)+v; } int secs_to_time(long p) { time t; return t.h=p/3600; p=p%3600; t.min=p/60; p=p%60; t.sec=p; }

Q.No: 7 Write the program that swaps the values. //M. NAVEED //CLASS BS(SE) //1562 //SESSION 2011_2015 #include<iostream.h> #include<conio.h> void swap(int& x,int& y); void main() { clrscr(); int a,b; cout<<"enter first number:"; cin>>a; cout<<"enter scond number:"; cin>>b; cout<<"values before swapping:\n"; cout<<"a="<<a<<endl;

cout<<"b="<<b<<endl; cout<<" swapping the values..."<<endl; swap(a,b); cout<<"Values after swapping"<<endl; cout<<"a="<<a<<endl; cout<<"b="<<b<<endl; getch(); } void swap(int& x,int& y) { int t; t=x; x=y; y=t; }