PRactice PROGRAMS
PRactice PROGRAMS
PRactice PROGRAMS
1) Fibonacci series:
#include<iostream>
using namespace std;
int main()
{
int i=0,n,t1=0,t2=1,t3;
cout<<"Enter the number of terms:"<<endl;
cin>>n;
if(n<=1)
{
c=0;
}
else
{
for(int i=2;i<n;i++)
{
if(n%i==0)
{
c=0;
}
break;
}
}
if(c==0)
{
cout<<n<<" is not a prime number"<<endl;
}
else if(c==1)
{
cout<<n<<" is a prime number"<<endl;
}
return 0;
}
3) Palindrome number:
#include<iostream>
using namespace std;
int main()
{
int n,og,rev=0,r;
cout<<"Enter a number:"<<endl;
cin>>n;
og=n;
while(n!=0)
{
r=n%10;
rev=rev*10+r;
n/=10;
}
if(og==rev)
{
cout<<og<<" is a palindrome"<<endl;
}
else
{
cout<<og<<" is not a palindrome"<<endl;
}
return 0;
}
4) Factorial:
#include<iostream>
using namespace std;
int main()
{
int fact=1,i=1,n;
cout<<"Enter a number:"<<endl;
cin>>n;
if(n==0)
cout<<"fact=1"<<endl;
else
{
while(i<=n)
{
fact*=i;
i++;
}
cout<<"fact = "<<fact<<endl;
}
return 0;
}
5) Armstrong number:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,og,r,d=0,sum=0;
cout<<"Enter a number:"<<endl;
cin>>n;
og=n;
while(og!=0)
{
og/=10;
++d;
}
og=n;
while(og!=0)
{
r=og%10;
sum+=pow(r,d);
og/=10;
}
if(sum==n)
{
cout<<n<<" is an Armstrong number"<<endl;
}
else
{
cout<<n<<" is not an Armstrong number"<<endl;
}
return 0;
}
6) Sum of Digits:
#include<iostream>
using namespace std;
int main()
{
int num,sum=0,r,og;
og=num;
while(num!=0)
{
r=num%10;
sum+=r;
num/=10;
}
return 0;
}
7) Reverse Number:
#include<iostream>
using namespace std;
int main()
{
int number;
cout<<"Enter a number: ";
cin>>number;
int reversedNumber=rev(number);
return 0;
}
int main()
{
int a, b;
return 0;
}
9) Matrix Multiplication:
#include <iostream>
using namespace std;
const int MAX_SIZE = 100; // Maximum size for matrices, adjust as needed
// Perform multiplication
for(int i = 0; i < rows1; ++i)
{
for(int j = 0; j < cols2; ++j)
{
for(int k = 0; k < cols1; ++k)
{
result[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
}
int main()
{
int mat1[MAX_SIZE][MAX_SIZE], mat2[MAX_SIZE][MAX_SIZE];
int result[MAX_SIZE][MAX_SIZE];
int rows1, cols1, rows2, cols2;
int main()
{
int decimalNumber;
return 0;
}
int main()
{
int n;
char current_char = 'A';
return 0;
}
int main()
{
int n;
cout << "Enter the number of rows (1 to 9): ";
cin >> n;
if (n < 1 || n > 9)
{
cout << "Invalid input! Number of rows should be between 1 and 9." <<
endl;
return 1;
}
return 0;
}
int main()
{
int n;
cout << "Enter the number of rows for Fibonacci triangle: ";
cin >> n;
return 0;
}
int main()
{
long long num;
return 0;
}