Need 1 on first row...what changes need to do

my code:

#include
using namespace std;
int main() {
int n;
cin>>n;

for(int i=1; i<=n; i++){
	int val=i-1;
	for(int cnt=1; cnt<=i; cnt++){
		if(cnt==1 || cnt==i){
			cout<<val;
		}else{
			cout<<"0";
		}
	}
	cout<<endl;
}
return 0;

}

@neelrai906
hello Neel,
add an if statement to check i=1 or not if it is 1 then print 1 and continue to next iteration

1 Like