Computer Science, asked by koushik18, 1 year ago

wap in java or c++ using for loop

Attachments:

Answers

Answered by sikhi
3


#include<stdio.h>

int main(){

int i,j,n,k;  

printf("Enter the range\n");

scanf("%d",&n);

k=n+1;

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

for(j=1,k=k-i;j<=i;j++){

printf("%d",k);

k++;

}

printf("\n");

}

return 0;

}

this will give output as:-

5
45
345
2345
12345


sikhi: hope it will help you
koushik18: thanks
Answered by anindyaadhikari13
2

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program in Java or C++ to display the following pattern.

5

4 5

3 4 5

2 3 4 5

1 2 3 4 5

\star\:\:\:\sf\large\underline\blue{Code:-}

The given code is written in Java Language.

import java.util.*;

class Pattern

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the number of rows for the pattern: ");

int n=sc.nextInt();

for(int i=n;i>=1;i--)

{

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

System.out.print(j+" ");

System.out.println();

}

}// end of main()

}// end of class.

Similar questions