Can u do a recursive function of this code Question How can i make this recuraive function in cpp help_outlinefullscreen check_circle Expert Answer thumb_up thumb_down Step 1 printing given pattern in c++ Step 2 #include int main() { int n=3, a=4; // increasing portion of the pattern for(int i=1; i<=n+1; i++) { // print space for(int j=i; j<=n; j++) { printf(" "); } // print digit for(int k=1; k<=2*i-1; k++) { if(k=1; i--) { // print space for(int j=n; j>=i; j--) { printf(" "); } // print digit for(int k=1; k<=2*i-1; k++) { if(k
Can u do a recursive function of this code
How can i make this recuraive function in cpp
Expert Answer
printing given pattern in c++
#include<iostream>
int main()
{
int n=3, a=4;
// increasing portion of the pattern
for(int i=1; i<=n+1; i++)
{
// print space
for(int j=i; j<=n; j++)
{
printf(" ");
}
// print digit
for(int k=1; k<=2*i-1; k++)
{
if(k<i) printf("%d",a--);
else if(k==i) printf("%d",a);
else printf("%d",++a);
}
// new line
printf("\n");
}
// decreasing portion of the pattern
for(int i=n; i>=1; i--)
{
// print space
for(int j=n; j>=i; j--)
{
printf(" ");
}
// print digit
for(int k=1; k<=2*i-1; k++)
{
if(k<i) printf("%d",a--);
else if(k==i) printf("%d",a);
else printf("%d",++a);
}
// new line
printf("\n");
}
return 0;
}
Step by step
Solved in 2 steps with 2 images