Question How can I give spaces between numbers? When I add a <<" "
after cout<<j
the pattern changed. Is there any other way to give spaces between numbers?
code
#include<iostream>
using namespace std;
int main(){
int i,j=1,space,star,n;
cin>>n;
i=1;
Looping
while(i<=n){
space=n-i;
while(space){
cout<<" ";
space--;
}
star=i;
while(star){
cout<<j<<" ";
j++;
star--;
}
cout<<"\n";
i++;
}
return 0;
}
output for n=4
1
23
456
78910
I want this output :-
1
2 3
3 4 5
7 8 9 10
Aucun commentaire:
Enregistrer un commentaire