You are on page 1of 10

1.

Write a code which calculate minimum and maximum element


from the array, input this array from the user.
Task#1;
#include<iostream>
using namespace std;
int main()
{
int a[10];
int max=a[0];
int min=999999;
int i=0;
int j=0;
cout<<"Enter elements of the array : ";
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(int i=0;i<10;i++)
{
for(;j<10;j++)
{
if(a[j]>max)
{
max = a[j];
}

}
for(int k=0;k<10;k++)
{
if(a[k]<min)
{
min = a[k];
}
}
}
cout<<"The Maximum element is : "<<max<<endl;
cout<<"The Minimum element is : "<<min;
}
Output#1;
2.Count the element of any character array.
Task#2;
#include<iostream>
using namespace std;
int main()
{
const int size=100;
char a[size];
int count=0;
cout<<"Please enter characters without spaces (upto 100) : ";
cin>>a;
for(int i=0;a[i]!='\0';i++)
{
if(a[i]>=65 && a[i]<=90 || a[i]>=97 && a[i]<=122) //The ASCII is
used for perfection of code not for anything else.
{
count++;
}
}
cout<<"No.of Characters are : "<<count;
}
Output#2;

3.Input your name and display it in reverse order.


Task#3;
#include<iostream>
using namespace std;
int main()
{
const int size= 100;
char a[size];
cout<<"Enter your name it'll be displayed in reverse order : ";
cin>>a;
cout<<"Thes reversed order is : ";
for(int i=size;i>=0;i--)
{
if(a[i]>=65 && a[i]<=90 || a[i]>=97 && a[i]<=122)
{
cout<<a[i];
}
else
continue;
}
}
Output#3;

4.Declare a character array, and initialize it to a suitable string. Use


a loop to change every other character to uppercase. Hint: In the
ASCII character set, values for uppercase characters are 32 less
than their lowercase counterparts.
Task#4;
#include<iostream>
using namespace std;
int main()
{
char h[10]={'H','a','s','n','a','i','n','R','a','j'};
for(int i=0;i<10;i++)
{
if(h[i]>=97 && h[i]<=122)
{
h[i]=h[i]-32;
cout<<h[i];
}
else
cout<<h[i];
}

}
Output#4;
5.Write a program that four arrays numbers, squares, cubes and
sums each consisting 10 elements. The numbers array stores the
values of its indexes, the squares array stores the square of its
indexes, the cube array stores the cubes of its indexes and sums
array stores the sum of corresponding indexes of three arrays.
The program should display the value of sums array and total of
all values in sums array.
Task#5;
#include<iostream>
using namespace std;
int main()
{
const int size=10;
int a[size];
int b[size];
int c[size];
int d[size];
int sum=0;
cout<<"Enter 10 digits : "<<endl;
for(int i=0;i<10;i++)
{
cin>>a[i];
b[i]=a[i];
c[i]=b[i];
d[i]=c[i];
}
cout<<"The indexes of array are as : ";
cout<<"Index[10] = { ";
for(int j=0;j<10;j++)
{
cout<<a[j];
if(j<9)
{
cout<<",";
}
else
continue;
}
cout<<" }"<<endl;

for(int i=0;i<10;i++)
{
b[i]=a[i]*a[i];
}
cout<<"The squares of indexes are : ";
cout<<"Square[10] = { ";
for(int s=0;s<10;s++)
{
cout<<b[s];
if(s<9)
{
cout<<",";
}
else
continue;
}
cout<<" }";
cout<<endl;
for(int i=0;i<10;i++)
{
c[i]=a[i]*a[i]*a[i];
}
cout<<"The cubes of indexes are : ";
cout<<"Cubes[10] = { ";
for(int s=0;s<10;s++)
{
cout<<c[s];
if(s<9)
{
cout<<",";
}
else
continue;
}
cout<<" }";
cout<<endl;
for(int k=0;k<10;k++)
{
d[k]=a[k]+b[k]+c[k];
sum=sum+d[k];
}
cout<<"The sums of corresponding indexes,squares,cubes are : ";
cout<<"Sum[10] = { ";
for(int k=0;k<10;k++)
{
cout<<d[k];
if(k<9)
{
cout<<",";
}
else
continue;
}
cout<<" }"<<endl;
cout<<"The total sum of all sum array values is : "<<sum;
}

Output#5;

6.Write a program that takes in 50 values and prints out the


highest, the lowest, the average and then all 50 input values,
one per line.
Task#6;
#include<iostream>
using namespace std;
int main()
{
const int size=50;
int a[size];
float average;
float sum=0;
int i=0;
int j=0;
int highest=0;
int lowest=999999;
cout<<"Enter 50 values : ";
for(i=0;i<size;i++)
{
cin>>a[i];
sum=sum+a[i];
}
for(int i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(a[j]>highest)
{
highest=a[j];
}
}
for(int k=0;k<size;k++)
{
if(a[k]<lowest)
{
lowest=a[k];
}
}
average=sum/size;
}
cout<<"The Highest number is : "<<highest<<endl;
cout<<"The Lowest number is : "<<lowest<<endl;
cout<<"The Average is : "<<average<<endl;
cout<<"The elements of the array are as under : "<<endl;
for(int l=0;l<size;l++)
{
cout<<a[l]<<endl;
}
}
Output#6.1;
Output#6.2;

You might also like