C++ Activity
C++ Activity
C++ Activity
Class:-
sy.bca(sci)
Roll.no:-20
Subject:-c++
Q1.Write a C++ program to print Floyd‟s
triangle.
23
456
7 8 9 10
Program:
#include<iostrea
m> using
namespace std;
int main()
{
int i, j,
num=1;
for(i=0; i<5;
i++)
cout<<num<<"
"; num++;
cout<<endl;
return 0;
}
Output:
23
456
7 8 9 10
11 12 13 14 15
program:
#include
<iostream>
using
namespace std;
int main()
{
int n, num, digit, rev = 0;
n = num;
do
+ digit; num =
num / 10;
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
palindrome."; else
return 0;
}
output:
number is a palindrome.
number is not a
palindrome.
program:
#include<iostrea
m> using
namespace std;
int main() {
if (num %
i == 0)
cout << i
return 0;
Output:
The factors of 20 are : 1 2 4 5 10 20
Program:
#include
<iostream>
using
namespace
std;
int main() {
cout<<"Enter a positive
for(int temp=num;
% 10;
if(sum == num)
cout<<num<<" is an Armstrong
number."; else
return 0;
Output:
370 370 is an
Armstrong number.
Q5.Write a C++ program to fibonacci
series. Program:
#include
<iostream>
using
namespace
x) { if((x==1)||
(x==0)) {
return(x);
}else {
return(fib(x-1)+fib(x-2));
int
main(
) { int
x,
i=0;
return 0;
Output:
hexadecimal.
Program:
#include<iostrea
m> using
namespace std;
int DecToHexDec(int
hexaDecNum[50];
int main()
{
int decimalNum, i;
i = DecToHexDec(decimalNum, 0);
cout<<"\nEquivalent Hexadecimal
cout<<hexaDecNum[i];
cout<<endl;
return 0;
int rem;
while(dec!
=0)
rem = dec
%16;
if(rem<10)
rem =
rem+48;
else
rem =
rem+55;
hexaDecNum[i
] = rem; i++;
dec = dec/16;
return i;
Output:
13C
Q7.Write a C++ program to generate multiplication table.
Program:
#include
<iostream> using
namespace std;
int
mai
n()
{ in
tn
= 8,
i;
cout << n << " * " << i << " = " << n * i <<
endl; return 0;
Output:
follows: 8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80
Program:
#include
<iostream>
using
namespace
std; int
main()
while (c1!=r2)
{
cout << "Error! column of first matrix not equal to row of
second."; cout << "Enter rows and columns for first matrix: ";
++i) for(j = 0;
j < c2; ++j)
mult[i][j]=0;
++i) for(j =
0; j < c2; +
+j)
mult[i][j]; if(j ==
c2-1)
return 0;
}
Output:
matrix: 3 2
matrix: 3 2
matrix: 2 3
matrix: 3 2
Enter elements of
matrix 1: Enter
elements a11: 3
Enter elements
a12: -2 Enter
elements a13: 5
Enter elements
a21: 3 Enter
elements a22: 0
Enter elements
a23: 4
Enter elements of
matrix 2: Enter
elements b11: 2
Enter elements
b12: 3 Enter
elements b21: -9
Enter
elements b22:
0 Enter
elements b31:
0 Enter
elements b32:
Output Matrix:
24 29
6 25
Q9.Write a C++ program to matrix
transpose. Program:
#include<iostre
am> using
namespace std;
int main() {
{3, 4} , {5, 6} };
cout<<"The matrix is:"<<endl;
for(i=0; i<r; +
+i) { for(j=0;
j<c; ++j)
cout<<a[i]
[j]<<" ";
cout<<endl;
cout<<endl;
for(i=0; i<r;
++i) for(j=0;
j<c; ++j) {
transpose[j][i] = a[i][j];
}
cout<<transpose[i][j]<<" ";
cout<<endl;
return 0;
Output:
12
34
56
135
246