Professional Documents
Culture Documents
#include <iostream>
int main() {
int n1 =0,n2=1,n3,i,number;
cin»number;
return 0;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
cout«n3«" printFibonacci(n-l);
int main(){
int n;
cin»n;
cout«"Fibonacci Series:
cout«"0 "«"1
0;
int n, i, c = 0;
{
if (n % i == 0)
{
C++;
if (c == 2)
else
return 0;
Palindrome program
#include <iostream>
int main()
int n,r,sum=O,temp;
cout«"Enterthe Number-';
cin»n;
temp=n;
while(n>0)
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
Factorial program
#include <iostream>
int main()
int i,fact=1,number;
cin»number;
for(i=1;i<=number;i++){
fact=fact*i;
return 0;
Armstrong Number
Armstrong number is a number that is equal to the sum of cubes of its
digits. For example 0,1,153, 370, 371 and 407 are the Armstrong
numbers.
#include <iostream>
int main()
int n,r,sum=0,temp;
cin»n;
temp=n;
while(n>0)
r=n%10;
sum=sum+(r*r*r);
n=n/10;
if(temp==sum)
else
int main()
cout«"Enter a number:
cin»n;
while(n!=0)
rem=n%10;
reverse=reverse*10+rem;
n/=10;
0;
swap two numbers without third variable
#include <iostream>
using namespace std;
int main()
{
int a=5, b=10;
cout«"Before swap a= "«a«" b= "«b«endl;
a=a+b; //a=15 (5+10)
b=a-b; //b=5 (15-10)
a=a-b;//a=10 (15-5)
cout«"After swap a= "«a«" b= "«b«endl; return 0;
}
#include <string.h>
int main()
//Initializing variable.
char str[100];
int i,vowels=0;
//Accepting input.
gets(str);
for(i=0;str[i];i++)
if(str[i]=-a’||
str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=
=T||str[i]=='O' ||str[i]=='U')
{
vowels++;