won’t be able to understand this please give me anther logic for this q
Manmohan loves pattern 1
Did you understand how the pattern is being formed?
no please explain me in easy way whole program
The number of values in each row = number of that row. And now if you look carefully, the odd-numbered rows only contain 1 and the even-numbered rows contain 1 at extremes only.
Try to code using this logic. It is an easy question.
why after if and else block we are using while loop
why can’t we direct solve it I don’t understand please clear the process
please reply me fast
please reply me why after if and else we are using while loop please reply me fast
and also in else statement why row-2 is used I won’t be able to understand please Clear my doughts
Send your code please
the same code which is solved in he video why col<=row-2 used
#include
using namespace std;
int main()
{
int n;
cin>>n;
int row=1;
while(row<=n){
int col=1;
if(row%2!=0){
while(col<=row){
cout<<1;
col=col+1;
}
}
else{
cout<<1;
while(col<=row-2){
cout<<0;
col=col+1;
}
cout<<1;
}
cout<<endl;
row=row+1;
}
return 0;
}
and why if else statement while loop is used explain me in full detail
First of all, did you dry run this code on the sample input?
col<=row-2 is because in the even numbered rows, we want to have 2 1s and row-2 0s.
Loops are used when we want to repeat a set of statements.
why int row=1 and after loop of row we are inputing int col=1; why not before loop we are inputing both row and col =1; why col is written after row<=n after that why please explain me
please reply me fast
hey please reply me fast
You can declare the variable col outside the while(row<=n) as well. But it is necessary to reset col to 1 because for every row, we have to start from its first column.
so how I do if I am taking before I won’t be able to do please do a program and explain me