CPP program to print Fibonacci Triangle

The below program is to print the Fibonacci Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int a,b,i,c,j; for(i=1; i<=5; i++) { a=0; b=2; cout<<b<<"\t"; for(j=1; j<i; j++) { c=a+b; cout<<c<<"\t"; a=b; b=c; } cout<<"\n"; } return 0; }#include <iostream.h> using namespace std; int main() { int a,b,i,c,j; … Read more

Categories CPP

CPP program to print Number Triangle

The below program is to print the Number Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int i,j,k,l; for(i=1;i<=5;i++) { for(j=1;j<=5-i;j++) { cout<<" "; } for(k=1;k<=i;k++) { cout<<k; } for(l=i-1;l>=1;l–) { cout<<l; } cout<<"\n"; } return 0; }#include <iostream.h> using namespace std; int main() { int i,j,k,l; for(i=1;i<=5;i++) … Read more

Categories CPP

CPP program to print Alphabet Triangle

The below program is to print the Alphabet Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { char ch=’a’; int i, j, k, l; for(i=1;i<=5;i++) { for(j=5;j>=i;j–) cout<< " "; for(k=1;k<=i;k++) cout << ch++; ch–; for(l=1;l<i;l++) cout<<–ch; cout<< "\n"; ch=’a’; } return 0; }#include <iostream.h> using namespace std; int … Read more

Categories CPP

CPP program to print Numbers in form of Characters

The below program is to print the word representation of a number in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int num,x; int tot = 0;   cout << "Enter the number: "; cin >> num;   while(num>0) { x = num%10; tot = tot*10 + x; num = … Read more

Categories CPP

CPP program to convert a decimal number into a binary number

Decimal System: A number system with base 10 i.e, numbers from 0-9 are used to represent a decimal number system. Binary System: A number system with base 2 i.e, only binary numbers 0 and 1 are used to represent a binary number system. Code: #include <iostream.h> using namespace std;   int main() { int arr[20]; … Read more

Categories CPP

CPP program to print Matrix Multiplication

The below program is to print multiplication of two matrices. The CPP cout object is used to output the result on the screen. Code: #include <iostream.h> using namespace std;   int main() { int a[2][3] = { {2, 5, 5}, {4, 0, 6} }; int b[3][2] = { {4, 5}, {4, 8}, {3, 9} }; … Read more

Categories CPP

CPP program to swap two numbers

The below program is to swap two numbers with and without using third variable. The CPP cout object is used to output the result on the screen. Swapping two numbers simply means interchanging the values of two numeric variables. Before Swapping, A = n1 B = n2 After Swapping, A = n2 B = n1 … Read more

Categories CPP

CPP program to reverse a number

The below program can be used to reverse a given number using a loop. The CPP cout object is used to output the result on the screen. Reverse Number of abcde = edcba. Code: #include <iostream.h> using namespace std;   int main() { int num, x = 0; int mod;   cout << "Enter a … Read more

Categories CPP

CPP program to print sum of digits

The below program gives the sum of all the digits in a variable using loop. The CPP cout object is used to output the result on the screen. Logic: Till the given Number is greater than 0. Remainder = Modulus of Number with 10 Total Sum = Adding Remainder into the Total Sum Number = … Read more

Categories CPP

CPP program to check for an Armstrong number

The below program checks for an Armstrong number using a loop. The CPP cout object is used to output the result on the screen. A number is called as an Armstrong number if the sum of the cubes of its digits is equal to the number itself. Armstrong Number: abc = (a*a*a) + (b*b*b) + … Read more

Categories CPP