Reverse of Number PDF
Reverse of Number PDF
me/campusdrive
This series is a mixture of 2 series - all the odd terms in this series form a Fibonacci series and all the
even terms are the prime numbers in ascending order.
The value N is a Positive integer that should be read from STDIN. The Nth term that is calculated by
the program should be written to STDOUT. Other than the value of Nth term, no other
characters/strings or message should be written to STDOUT.
For example, when N = 14, the 14th term in the series is 17. So only the value 17 should be printed to
STDOUT.
#include<iostream>
using namespace std;
#define MAX 1000
void fibonacci(int n)
{
int i, t1 = 0, t2 = 1, nextTerm;
for (i = 1; i<=n; i++)
{
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
cout << t1;
}
void prime(int n)
{
int i, j, flag, count =0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
2. Given a series whose even term creates a separate geometric series and odd term creates another
geometric series.
#include<iostream>
using namespace std;
int main()
{
int n, i, r1, r2;
cout << "nEnter the total number of terms : ";
cin >> n;
cout << "nEnter the common ratio for GP - 1 : ";
cin >> r1;
cout << "nEnter the common ratio for GP - 2 : ";
cin >> r2;
cout << "nThe series isn";
int a = 1, b = 1;
if(n % 2 == 0)
{
for(i = 0; i < n/2; i++)
{
cout << a << " ";
a = a * r1;
cout << b << " ";
b = b * r2;
}
}
else
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
{
for(i = 0; i < n/2; i++)
{
cout << a << " ";
a = a * r1;
cout << b << " ";
b = b * r2;;
}
cout << a << " ";
}
cout << endl;
}
Program to find the area of a circle is discussed here. Area of the circle can be found using the
formula, A = πr2 where r is the radius of the circle. When the radius of the circle is known, the area of
the circle can be calculated using the formula mentioned.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
#include <iostream>
int main()
int year;
if(year%4 == 0)
if( year%100 == 0)
if ( year%400 == 0)
else
else
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
else
return 0;
5. GCD of two numbers | Program to find the GCD or HCF of two numbers
#include<iostream>
int main()
int a,b,gcd;
int i;
gcd = i;
cout << “\nGCD of “<< a << ” and ” << b << ” is ” << gcd;
return 0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
#include<stdio.h>
int main()
int n,i;
scanf(“%d”,&n);
if(n % i ==0)
break;
else
return 0;
#include <iostream>
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
int main()
int a, b, i, flag;
cin >> a;
cin >> b;
cout << “\nPrime Numbers between ” << a << ” and ” << b <<” : “;
while (a < b)
flag = 0;
if(a % i == 0)
flag = 1;
break;
if (flag == 0)
++a;
return 0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
#include<iostream>
int main()
int n,i;
int fact,rem;
cin >> n;
int sum = 0;
int temp = n;
while(n)
i = 1,fact = 1;
rem = n % 10;
fact = fact * i;
i++;
n = n / 10;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
if(sum == temp)
else
return 0;
#include<iostream>
int is_Palindrome(int );
int n;
int main()
int palindrome;
cin >> n;
palindrome = is_Palindrome(n);
if(palindrome == 1)
else
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
return 0;
if(aj != 0)
else if(sum == n)
return 1;
else
return 0;
#include<iostream>
int main()
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
temp = number;
while (temp != 0)
temp /= 10;
++n;
temp = number;
while (temp != 0)
remainder = temp ;
temp /= 10;
if(result == number)
else
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
return 0;
// C++ program to print the Armstrong numbers between the two intervals
#include <iostream>
#include <math.h>
int main()
cout << “\nArmstrong numbers between ” << start << ” and ” << end << ” are : “;
temp2 = i;
temp1 = i;
while (temp1 != 0)
temp1 /= 10;
++n;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
while (temp2 != 0)
temp2 /= 10;
if (result == i) {
n = 0;
result = 0;
return 0;
#include<iostream>
int main()
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
int sum = 0, n;
int a = 0;
int b = 1;
cin >> n;
while(sum <= n)
a = b; // swap elements
b = sum;
return 0;
#include
while (n!=0)
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
remainder = n ;
n /= 10;
decimal += remainder*pow(2,i);
++i;
return decimal;
int main()
long int n;
cin >> n;
return 0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
#include <iostream>
int main()
int a, b, i, flag;
cin >> a;
cin >> b;
cout << “\nPrime Numbers between ” << a << ” and ” << b <<” : “;
while (a < b)
flag = 0;
if(a % i == 0)
flag = 1;
break;
if (flag == 0)
++a;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
return 0;
#include <iostream>
int main()
cin >> n;
while(n != 0)
rem = n ;
n /= 10;
return 0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
#include <iostream>
int main()
int i, j, count = 0;
count++;
j = count - 1;
rev[i] = str[j];
j--;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
**
***
****
*****
******
#include <iostream>
int main()
int i, j,n;
cin >> n;
return 0;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
#include <iostream>
int main()
int n, c, k, space = 1;
cin >> n;
space = n – 1;
cout << ” “;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
space--;
space = 1;
cout << ” “;
space++;
return 0;
#include <bits/stdc++.h>
int main()
int n,i;
cin >> n;
int arr[n];
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
sort(arr, arr+n);
return 0;
#include<iostream>
if (n==0 || n==1)
return n;
int temp[n];
int j = 0;
int i;
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
if (arr[i] != arr[i+1])
temp[j++] = arr[i];
temp[j++] = arr[n-1];
arr[i] = temp[i];
return j;
int main()
int n;
cin >> n;
int arr[n];
int i;
n = remove_duplicate_elements(arr, n);
Telegram - https://t.me/tcsnqtexam
Telegram - https://t.me/campusdrive
return 0;
Telegram - https://t.me/tcsnqtexam