Posts

Showing posts from October, 2018

CS - Program to find a given number is Perfect Number or not?

Image
Objective: To find the given number is Perfect Number or not? Program should accept a number using C++ and find out it is Perfect Number or not. What are Perfect Numbers? Perfect Numbers are those numbers who's sum of individual factors is same as the number itself, with an  exception the number itself should not be included as one of the factors. C++ Solution (Keeping in mind the students of class XI/XII having Computer Science with C++ as one of their subject) #include<iostream.h> #include<conio.h> int chk_PerfectNumber(int n) { int sum=0; for(int i = 1; i < n; i++)         {             if(n % i == 0)             {                 sum = sum + i;             }         }         if(sum == n)         {             return 1;         }         else         {             return 0;         } } void main() {          clrscr();          int n;          cout<<"\nEnter the number to find it is Perfec

CS - Program to generate Fibonacci Series

Write a program to generate a Fibonacci series up to a given number using C++? First of all we need to know -  What is Fibonacci Series?   It is a series of numbers that follows some pattern generated by adding previous two numbers, where first two numbers are 0 and 1. Fibonacci series has lots of uses in our life, you can easily find them on internet, just by googling it. But I have kind brought them on a single page - Click here to get more information about Fibonacci series.  C++ Program for generating Fibonacci Series (using while loop): #include<iostream.h> void main() {          int N, a=0,b=1,c=a+b;          clrscr();          cout<<"\nEnter the Upper Limit: ";          cin>>N;          cout<<a<<" "<<B<<" ";          while(c<=N)          {                 cout<<c<<" "                 a=b;                 b=c;                 c=a+b;