Practice 1
(Square)
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a[5];
int i,j;
cout<<"Enter Numbers to Find their squares: "<<endl;
for(i=1; i<=5; i++)
{
cin>>a[i];
a[i]=i*i ;
}
cout<<"===Square of Numbers==="<<endl;
for(i=1; i<=5; i++)
{
cout<<"\n"<<a[i];
}
getch();
}
Practice 2
(Even or odd)
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
int a[5];
int i,j;
cout << "===Enter Five Element===" << endl;
for (i=0; i<5; i++)
{
cin >> a[i];
}
cout << "===Check Whether the Number is Even or odd===" << endl;
for (j=0; j<5; j++)
{
if (a[j] % 2 == 0)
{
cout << "The number is even " <<j+1<<endl;
}
else
{
cout << "The number is odd " <<j+1<< endl;
}
}
_getch();
Practice 3
(Arithmetic calculation)
#include<conio.h>
#include<iostream>
using namespace std;
void main(void)
{
int a[5];
int b[5];
int s[5];
int i;
cout << "==Enter First Element here==" << endl;
for (i = 0; i < 5; i++)
{
cout << "Enter Element " <<i+1<< endl;
cin >> a[i];
}
cout << "==Enter Second Element here==" << endl;
for (i = 0; i < 5; i++)
{
cout << "Enter Element " << i + 1 << endl;
cin >> b[i];
}
for (i = 0; i < 5; i++)
{
s[i] = a[i] + b[i];
cout << "Sum is " << s[i] << endl;
}
_getch();
}
Practice 4
(Square root)
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main() {
double num[5];
cout << "(Values must be in square)" << endl;
for (int i = 0; i < 5; i++)
{
cout << "Enter value " <<i+1<<endl;
cin >> num[i];
num[i] = sqrt(num[i]);
}
cout << "===Square root===" << endl;
for (int i = 0; i < 5; i++)
{
cout << "Square root of value " << i + 1 << " is" << endl;
cout << num[i] << endl;
}
_getch();
}
Practice 5
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a[5];
int i;
int fact = 1, num = 1;
cout << "Enter five number: " << endl;
for (i = 0; i < 5; i++)
{
cin >> a[i];
}
for (i = 0; i < 5; i++)
{
if (a[i] < 10)
{
for (num = 1; num <= a[i]; num++)
{
fact = fact*num;
}
cout << "Factorial is \n" << fact << endl;
}
fact = 1;
}
_getch();
}