Write a program to display the following pattern:
9
9 7
9 7 5
9 7 5 3
9 7 5 3 1
pls fast pls fast
Answers
Answered by
3
Required Answer:-
Question:
- Write a program to display the given pattern.
Solution:
Here comes the program.
1. In Java.
public class Pattern {
public static void main(String[] args) {
int i, j;
for(i=9;i>=1;i-=2) {
for(j=9;j>=i;j-=2)
System.out.print(j+" ");
System.out.println();
}
}
}
2. In Python.
for i in range(9,0,-2):
for j in range(9,i-1,-2):
print(j,end=" ")
print()
3. In C
#include <stdio.h>
int main() {
int i, j;
for (i=9;i>=1;i-=2) {
for(j=9;j>=i;j-=2)
printf("%d ", j);
printf("\n");
}
return 0;
}
4. In C++
#include <iostream>
using namespace std;
int main() {
int i,j;
for(i=9;i>=1;i-=2) {
for(j=9;j>=i;j-=2)
cout <<j<<" ";
cout << endl;
}
return 0;
}
Algorithm:
- START
- Iterate i in range 9 to 1.
- Iterate j in range 9 to i.
- Display the value of j. Decrease the value of j by 2.
- Print a new line after displaying the row.
- Decrease the value of i by 2.
- STOP
See the attachment for output ☑.
Attachments:
Similar questions