Object
Oriented Programming
Assignment
# 01
Q1: What is the principle advantage of an un-sized
array?
ANS:
The Advantage of an un-sized array is that we can save
number of elements in array by our choice as by defining the array we are
restricted to use only the desired size of an array.
Q2: Explain the difference between the prefix and
postfix form of increment operator?
ANS:
The difference between prefix and postfix is that prefix
increment operator increment the number first and then print it.
While in case of postfix
increment operator it print the number first and then made an increment.
Q3: Write a program that averages the absolute value
of first ten values entered by user. Display the result.
ANS:
Program Code:
#include <iostream>
using namespace std;
int main()
{
int arr[10];
int i,j;
float sum,avg;
sum=0;
for(i=0;i<10;i++)
{
cout<<"Enter the array's "<<i<<" element: ";
cin>>arr[i];
sum=sum+arr[i];
}
avg=sum/10;
cout<<"The
Average is "<<avg<<endl;
}
Q4: Write a program that finds all the prime number
between 1 to 100. Display the result.
ANS:
Program Code:
#include <iostream>
using namespace std;
int main ()
{
for (int i=2; i<100;
i++)
for (int j=2; j<i;
j++)
{
if (i % j == 0)
break;
else if
(i == j+1)
cout <<"Prime Numbers are "<<
i <<endl;
}
return 0;
}
Q5: Write a program that…….. ? ?
ANS:
Program Code:
#include <iostream>
using namespace std;
void main()
{int i,j,k,l;
k=00;
l=00;
for(i=0;i<6;i++)
{
cout<<endl<<" "<<k;
l=k+1;
k=k+10;
for(j=0;j<5;j++)
{
cout<<" "<<l;
l=l+1;
}}cout<<endl;}
0 comments:
Post a Comment