In: Computer Science
Make 2 hard programming (1 about pattern and 1 about anything) problem in c++ that can be solved in around 30 minute
give the problem + the answer please
i need for learning c++
#include <iostream>
using namespace std;
int main(){
int n, i, j, space = 1;
cout<<"Enter size: ";
cin>>n;
space = n - 1;
// prints the upper part
for (j = 1; j <= n; j++)
{
for (i = 1; i <= space; i++)
{
cout<<"*";
}
space--;
for (i = 1; i <= 2 * j - 1; i++)
{
if(i==1 || i==2*j-i)
cout<<"*";
}
cout<<endl;
}
space = 1;
// prints the lower part
for (j = 1; j <= n - 1; j++)
{
// prints the spaces
for (i = 1; i <= space; i++)
{
cout<<"*";
}
space++;
// prints the stars
for (i = 1; i <= 2 * (n - j) - 1; i++)
{
if(i==1 || i==(2*n-j)-1)
cout<<"*";
}
cout<<endl;
}
}
Answer 2:
#include <iostream>
using namespace std;
int main(){
int start,end;
cout<<"Enter start and end ranges to print Prime numbers : ";
cin>>start;
cin>>end;
//iterating in range
for(int i=start;i<end;i++){
int count=0;
//checking for prime
for(int j=1;j<=i;j++){
//checking for factors
if(i%j==0){
count++;
}
}
//if factors are 2 than it is prime
if(count==2)
cout<<i<<" ";
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me