Skip to main content

First Sheet solution raman classes Patterns

                       Patterns


#include<iostream>
using namespace std;
/* Question-1
n=4
*
**
***
****
*/
half_triangle(int n){
cout<<endl<<" half_triangle "<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
cout<<"*";
}
cout<<endl;
}
}

/* Question-2
n=5
1
2 3
4 5 6
7 8 9 10
*/
half_triangle_1_10(int n){
cout<<endl<<" half_triangle_1-10 "<<endl;
int c=1;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
cout<<c<<" ";
c++;
}
cout<<endl;
}
}

/*
Question-3
n=4
0
1 0
1 0 1
0 1 0 1
*/
binary_number_half_triangle(int n){
cout<<endl<<" binary_number_half_triangle "<<endl;
int c=0;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
if(c==0){
cout<<c<<" ";
c++;
}
else{
cout<<c<<" ";
c--;
}
}
cout<<endl;
}
}

/*
Question-4 
number_diffrent_form_half_triangle
n=5
0
2  1
3  4  5
9  8  7  6
10 11 12 13 14
*/
number_diff_form_half_triangle(int n){
cout<<endl<<" number_diff_form_half_triangle "<<endl;
int c=0;
for(int i=0;i<n;i++){
int s=c+i;
if(i%2==0){
for(int j=0;j<=i;j++){
cout<<c<<" ";
c++;
}
cout<<endl;
}
else{
for(int j=0;j<=i;j++){
cout<<s<<" ";
s--;
}
c=c+i+1;
cout<<endl;
}
}
}

/*
Question - 5
Reverse Number Half Triangle -
n=4
1
3 2
6 5 4
10 9 8 7
*/
int reverse_half_triangle(int n){
cout<<endl<<" reverse_half_triangle "<<endl;
int c=1;
for(int i=0;i<n;i++){
int s=c+i;
for(int j=0;j<=i;j++){
cout<<" "<<s<<" ";
s--;
c++;
}
cout<<endl;
}
}

/*
Question - 6
n=4
1
-2 -3
4  5  6
-7 -8 -9 -10 
*/
int half_triangle_pos_neg(int n){
cout<<endl<<" half_triangle_positive_number_negative_number "<<endl;
int c=1;
for(int i=0;i<n;i++){
if(i%2==0){
for(int j=0;j<=i;j++){
cout<<" "<<c<<" ";
c++;
}
cout<<endl;
}
else{
int a=-1;
for(int j=0;j<=i;j++){
cout<<c*a<<" ";
c++;
}
cout<<endl;
}
}
}

int main(){
int n;
cin>>n;
/* 1
Question-1
*/
cout<<endl;
half_triangle(n);
cout<<endl;
/*
Question-2
*/
half_triangle_1_10(n);
cout<<endl;
cout<<endl;
/*
Question-3
*/
binary_number_half_triangle(n);
cout<<endl;
cout<<endl;
/*
Question-4
*/
number_diff_form_half_triangle(n);
cout<<endl;
/*
Question-5
*/
reverse_half_triangle(n);
cout<<endl;
/*
Question-6
*/
half_triangle_pos_neg(n);
cout<<endl;
cout<<endl;
return 0;
}

                                      OUTPUT SCREEN -







Comments

Popular posts from this blog

Open_cv_first_project

Step 1 - connect local server first (click on connect button) install packages commands are there.. command (i) !pip install cmake dlib face_recognition numpy opencv-python command (ii) !pip install opencv-python Step 2 - connect google drive folder where your picture uploaded. command (i)  from google.colab import drive command (ii) drive.mount('/gdrive/')  => click on link which show in your screen and allow all services than copy paist link those you get in screen  then your drive will be connect with google colab. command (iii) %cd /gdrive/My Drive/Open CV Project => using this connect your drive folder.. command (iv) ls => this command show you those images names on screen. step 3 - show image on screen. command (i)  import cv2 command (ii) from google.colab.patches import cv2_imshow command (iii) image = cv2.imread('test.jpg') => read image using this command and store one variable (image) command (iv) c...