0% found this document useful (0 votes)
34 views7 pages

Zrererejkkkkcdcd

This document contains C++ code examples for calculating the lowest common multiple and greatest common divisor of two numbers, determining if a number is a palindrome, Armstrong number, generating the Fibonacci series, and checking if a number is prime. The code examples demonstrate the use of basic C++ features like loops, conditionals, input/output streams to solve these mathematical problems.

Uploaded by

Inam Ur Rehman
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)
34 views7 pages

Zrererejkkkkcdcd

This document contains C++ code examples for calculating the lowest common multiple and greatest common divisor of two numbers, determining if a number is a palindrome, Armstrong number, generating the Fibonacci series, and checking if a number is prime. The code examples demonstrate the use of basic C++ features like loops, conditionals, input/output streams to solve these mathematical problems.

Uploaded by

Inam Ur Rehman
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/ 7

Zrererejkkkkcdcd

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