1. #include<stdio.
h>
#include<conio.h>
void main()
{
int x, y, n;
char ch;
printf("\n Enter number of Rows");
scanf("%d",&n);
for(x = 1;x<= n;x++)
{
printf("\n");
ch = 'A';
for(y = 1;y<=x;y++)
{
printf("\t%c",ch);
ch++;
}
}
getch();
Output
AB
ABC
ABCD *
\
4. #include <iostream>
using namespace std;
int main()
{
int low, high, i, flag;
cout << "Enter two numbers(intervals): ";
cin >> low >> high;
cout << "Prime numbers between " << low << " and " << high << "
are: ";
while (low < high)
{
flag = 0;
for(i = 2; i <= low/2; ++i)
{
if(low % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
cout << low << " ";
++low;
}
return 0;
}
Output
Enter two numbers(intervals): 20 50 Prime numbers between 20 and 50
are: 23 29 31 37 41 43 47
5. #include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter a positive integer: ";
cin >> n;
for (int i = 1; i <= 10; ++i) {
cout << n << " * " << i << " = " << n * i << endl;
}
return 0;
}
Output
Enter an integer: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
4. #include <iostream>
using namespace std;
int main()
{
int a[10][10], trans[10][10], r, c, i, j;
cout << "Enter rows and columns of matrix: ";
cin >> r >> c;
// Storing element of matrix entered by user in array a[][].
cout << endl << "Enter elements of matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter elements a" << i + 1 << j + 1 << ": ";
cin >> a[i][j];
}
// Displaying the matrix a[][]
cout << endl << "Entered Matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << " " << a[i][j];
if(j == c - 1)
cout << endl << endl;
}
// Finding transpose of matrix a[][] and storing it in array
trans[][].
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
trans[j][i]=a[i][j];
}
// Displaying the transpose,i.e, Displaying array trans[][].
cout << endl << "Transpose of Matrix: " << endl;
for(i = 0; i < c; ++i)
for(j = 0; j < r; ++j)
{
cout << " " << trans[i][j];
if(j == r - 1)
cout << endl << endl;
}
return 0;
}
Output
2 exersice
#include<iostream.h>
#include<conio.h>
const float pi=3.14;
float area(float n,float b,float h)
{
float ar;
ar=n*b*h;
return ar;
}
float area(float r)
{
float ar;
ar=pi*r*r;
return ar;
}
float area(float l,float b)
{
float ar;
ar=l*b;
return ar;
}
void main()
{
float b,h,r,l;
float result;
clrscr();
cout<<\nEnter the Base & Hieght of Triangle: \n;
cin>>b>>h;
result=area(0.5,b,h);
cout<<\nArea of Triangle: <<result<<endl;
cout<<\nEnter the Radius of Circle: \n;
cin>>r;
result=area(r);
cout<<\nArea of Circle: <<result<<endl;
cout<<\nEnter the Length & Bredth of Rectangle: \n;
cin>>l>>b;
result=area(l,b);
cout<<\nArea of Rectangle: <<result<<endl;
getch();
}
#include <iostream.h>
#include <conio.h>
inline int cube(int r) {
return r*r*r;
void main() {
clrscr();
int r;
cout<<"PROGRAM TO COMPUTE CUBE\n";
cout<<"Enter value to compute cube: ";
cin>>r;
cout<<"cube of the number: "<<cube(r);
getch();