Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Computer Programming Assignment

The document contains C++ code for 6 computer programming assignments: 1) calculating the lowest common multiple (LCM) of two numbers, 2) calculating the greatest common divisor (GCD) of two numbers, 3) checking if a number is a palindrome, 4) checking if a number is an Armstrong number, 5) printing the Fibonacci series up to a given number of terms, and 6) checking if a number is prime. Each program includes the necessary header files, defines the main function, gets input from the user, performs the relevant calculation or check, and prints the output.

Uploaded by

Inam Ur Rehman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Computer Programming Assignment

The document contains C++ code for 6 computer programming assignments: 1) calculating the lowest common multiple (LCM) of two numbers, 2) calculating the greatest common divisor (GCD) of two numbers, 3) checking if a number is a palindrome, 4) checking if a number is an Armstrong number, 5) printing the Fibonacci series up to a given number of terms, and 6) checking if a number is prime. Each program includes the necessary header files, defines the main function, gets input from the user, performs the relevant calculation or check, and prints the output.

Uploaded by

Inam Ur Rehman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER PROGRAMMING ASSIGNMENT

Name : Inam Ur Rehman

Class: BEMTS 2-C

Teacher: Ms. Hurriat Ali


L.C.M of Two Numbers:

#include <iostream>

#include<iomanip>

#include<conio.h>

#include<string>

using namespace std;

int main()

{ int a, b;

cout <<"Enter first number: ";

cin >> a;

cout << "Enter second number: ";

cin >> b;

int c=min(a , b);

int GCD=1;

int i=1;

while (i<=c)

{i++;

if (a%i==0 && b&i==0)

GCD = max(GCD , i);}

int LCM = (a*b)/GCD;

cout << "LCM of two numbers is: " << LCM << endl;

system ("pause");
}

-----------------------------------------------------------------------------------

G.C.D of Two Numbers:

#include <iostream>

using namespace std;

int main()

{ int a, b;

cout << “Enter first number: “;

cin >> a;

cout << “Enter second number: “;

cin >> b;

int min(a,b);

int GCD=1;

int i=1;

while (i<=c)

{i++;

if (a%i==0 && b&i==0)

GCD = max(GCD , i);}

cout << “G.C.D of Two Numbers is : “ << GCD << endl;

system (“pause”);

return 0;

}
----------------------------------------------------------------------------------

Palindrome Number:

#include <iostream>

using namespace std;

int main()

int palindrome, reverse=0, num=0, check;

cout << “Enter a Number: “;

cin >> palindrome;

check = palindrome;

int i=1;

while (palindrome =0)

i++;

num = palindrome %10;

palindrome = palindrome /10;

reverse = num + (reverse * 10 );

If (reverse == check )

cout << “Number is Palindrome.” << endl ;

else cout << “Number is not Palindrome.” << endl ;

system (“pause”) ;

return 0;
}

-----------------------------------------------------

Armstrong Number:

#include <iostream>

using namespace std;

int main()

{ int armstrong , num=0 ,result=0, check;

cout << "Enter a number: ";

cin >> armstrong;

check = armstrong;

int i=1;

while (armstrong !=0)

i++;

num = armstrong %10;

armstrong = armstrong/10;

result=result+(num*num*num);

if (result==check)

cout << "Number is armstrong." << endl ;

else cout << "Number is not armstrong." << endl;

system ("pause");

return 0;
}

----------------------------------------------

Fabonacci Series:

#include <iostream>

using namespace std;

int main()

{int members,first=0,second=1,third;

cout << "Enter number of members of series: ";

cin >> members;

int i=0;

while (i<members-1)

i++;

if ( i==0)

cout << first <<"," <<second ;

else {third=first+second;

first=second;

second=third;

cout << "," << third ;

cout << endl;

system ("pause");
return 0;

----------------------------------------------

Prime Number:

#include <iostream>

using namespace std;

int main()

{int number , count =0;

cout << "Enter a number: ";

cin >> number;

int i=1;

while (i<=number)

i++;

if (number%i==0)

count++;}

if (count==2)

cout << "Number is prime.";

else cout << "Number is not prime." << endl;

system ("pause");

return 0;

You might also like