Computer Science, asked by aishwaryasangade1, 9 months ago

Write a program to print the following pattern.
Sample Input:
5
Sample Output:
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15

Answers

Answered by chandrasayan05subhra
5

ANSWER:

#include<stdio.h>

int main()

{

int a,b,c,d,e;

a=1;

b=2*3;

c=4*5*6;

d=7*8*9*10;

e=11*12*13*14*15;

printf("%d\n",a);

printf("%d\n",b);

printf("%d\n",c);

printf("%d\n",d);

printf("%d\n",e);

return 0;

}

Answered by anagasatyasri710
20

Answer:

#include<iostream>  

using namespace std;  

void printPattern(int n)  

{  

   int j, k = 0;  

   for (int i=1; i<=n; i++)  

   {  

       if (i%2 != 0)  

       {  

           for (j=k+1; j<k+i; j++)  

               cout << j << "*";  

           cout << j++ << endl;  

           k = j;      

       }  

       else

       {  

           k = k+i-1;  

           for (j=k; j>k-i+1; j--)  

               cout << j << "*";  

           cout << j << endl;      

       }  

   }  

}  

int main()  

{  

   int n;

  cin>>n;

   printPattern(n);  

   return 0;  

}  

Similar questions