0% found this document useful (0 votes)
55 views10 pages

University of Wah: Lab-Assignment

This document contains 7 programming tasks completed by a student for a university lab assignment. Each task involves writing code to solve a programming problem and outputting the result. The tasks include calculating a factorial, checking if a number is even/odd/prime, determining if one number is a multiple of another, converting a decimal number to binary, reversing a number, finding the lowest common multiple of two numbers, and printing a Pascal's triangle.

Uploaded by

Muhammad inshal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views10 pages

University of Wah: Lab-Assignment

This document contains 7 programming tasks completed by a student for a university lab assignment. Each task involves writing code to solve a programming problem and outputting the result. The tasks include calculating a factorial, checking if a number is even/odd/prime, determining if one number is a multiple of another, converting a decimal number to binary, reversing a number, finding the lowest common multiple of two numbers, and printing a Pascal's triangle.

Uploaded by

Muhammad inshal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

UNIVERSITY OF WAH

LAB-ASSIGNMENT
Mehwish Tariq Khawaja

UW-18-PHY-BS-068

Submitted to: Ma’am Kainat Ibrar

Task 1:

#include<iostream> using

namespace std;

void fact(int n); int

main()

{ int

n;

cout<<"Enter any number = "<<endl;

cin>>n; fact(n);

void fact(int n)

{ int i,fact; fact=1; for(i=1; i<=n; i++) fact=fact*i;

cout<<"The factorial of "<<n<<" is "<<fact<<endl;

Result:
Task 2:

#include<iostream>

using namespace std;

void check(int a); int

main()

{ int

n;

cout<<"Enter any number = "<<endl;

cin>>n; check(n);

void check(int a)

int m,b; if(a%2==0)

cout<<"Even number";

if(a%2==1)

cout<<"Odd number";

m=a/2;

for(b=2;b<m;b++)

if(a%b==0)

break;

cout<<endl; if(a%b!=0)

cout<<"Prime number";

Result:
Task 3:

#include<iostream> using

namespace std; void

mult(int a, int b); int

main()

{ int x,

y;
cout<<"Enter first number = "<<endl;

cin>>x; cout<<"Enter second number =

"<<endl; cin>>y; mult(x,y);

void mult(int a, int b)

if(b%a==0) cout<<a<<" is multiple of

"<<b<<endl; else cout<<a<<" is not

multiple of "<<b<<endl;

Result:

Task 4: #include

<iostream> using

namespace std;
long decimalToBinary(long n);

int main()

long decimal,n; cout <<"Enter a decimal number = "; cin

>> decimal; cout << "Binary number = " <<

decimalToBinary(decimal); decimalToBinary(n);

long decimalToBinary(long n)

{ int remainder; long binary =

0, i = 1; while(n != 0)

remainder = n%2; n

= n/2;

binary= binary + (remainder*i); i

= i*10;

return binary;

Result:
Task 5:

#include<iostream> using

namespace std;

int reverse(int n);

int main()

int n=0, t=0;

cout<<"Enter Number: ";

cin>>n;

t=reverse(n); cout<<"Reverse number

is: " <<t <<endl; reverse(n);

int reverse(int n)

int temp=0, rev=0;

while(n!=0)

temp=n%10;

rev=(rev*10)+temp;

n=n/10;
}

return rev;

Result:

Task 6:

#include<iostream> using

namespace std;

void lcm(int,int);

int main()

{ int

x,y;

cout<<”Enter two numbers: “;

cin>>x>>y; lcm(x,y); return

0;

}
void lcm(int x,int y)

{ int

I,j;

I=x;

J=y;

while(i!=j)

if(I < j)

I=i+x;

else

J=j+y;

cout<<”\nL.C.M of “<<x<<” and “<<y<<” is “<<I;

Result:
Task 7:

#include<iostream>

using namespace std;

long tri(int); int

main()

{ int i,j,x,m;

for(i=0;i<5;++i)

for(j=1;j<=(5-i-1);++j)

cout<<" ";

for(m=0;m<=i;++m)

cout<<tri(i)/(tri(i-k)*tri(k))<<" ";

}
cout<<"\n";

return 0;

tri(x);

long tri(int x)

{ int i;

long f=1;

for(i=1;i<=x;++i)

{ f=f

*i;

return f;

Result:

The End

You might also like