Lalit C++
Lalit C++
#include<iostream>
using namespace std; int
main()
{
int i, j, num=1;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
Output:
1
23
456
7 8 9 10
11 12 13 14 15
#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
n = num;
do
{
digit = num % 10;
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
return 0;
}
output:
#include<iostream>
using namespace std; int
main() {
int num = 20, i;
cout << "The factors of " << num << " are : "; for(i=1;
i <= num; i++) {
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() {
if(sum == num)
return 0;
}
Output:
#include <iostream>
using namespace std;
int fib(int x)
{ if((x==1)||(x==0)) {
return(x);
}else {
return(fib(x-1)+fib(x-2));
}
namespace std;
char hexaDecNum[50];
int main()
int decimalNum, i;
cin>>decimalNum;
i>=0; i--)
cout<<hexaDecNum[i];
cout<<endl;
return 0;
=0)
{
rem = dec%16;
if(rem<10)
rem = rem+48; else
rem = rem+55;
hexaDecNum[i] = rem;
i++;
dec = dec/16;
return i;
Output:
}
Output:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter rows and columns for first matrix: "; cin
>> r1 >> c1;
cout << "Enter rows and columns for second matrix: "; cin
>> r2 >> c2;
while (c1!=r2)
cout << "Error! column of first matrix not equal to row of second."; cout
<< "Enter rows and columns for first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and columns for second matrix: ";
cin >> r2 >> c2;
}
cout << endl << "Enter elements of matrix 1:" << endl;
for(i = 0; i < r1; ++i)
for(j = 0; j < c1; ++j)
cout << "Enter element a" << i + 1 << j + 1 << " : "; cin
>> a[i][j];
}
cout << endl << "Enter elements of matrix 2:" << endl;
for(i = 0; i < r2; ++i)
for(j = 0; j < c2; ++j)
cout << "Enter element b" << i + 1 << j + 1 << " : "; cin
>> b[i][j];
}
for(i = 0; i < r1; ++i) for(j
= 0; j < c2; ++j)
{
mult[i][j]=0;
return 0;
Output:
Output Matrix:
24 29
6 25
Q9.Write a C++ program to matrix transpose.
Program:
#include<iostream>
using namespace std;
int main() {
int transpose[10][10], r=3, c=2, i, j; int
a[3][3] = { {1, 2} , {3, 4} , {5, 6} };
cout<<"The matrix is:"<<endl;
cout<<endl; for(i=0;
i<r; ++i) for(j=0;
j<c; ++j) {
transpose[j][i] = a[i][j];
}
Output:
The matrix is:
12
34
56