1 solutions
-
0
C :
#include<stdio.h> int main(){ char c[5][5]={{' ',' ','*',' ',' '}, {' ','*',' ','*',' '}, {'*',' ',' ',' ','*'}, {' ','*',' ','*',' '}, {' ',' ','*',' ',' '}}; int i,j; for(i=0;i<5;i++){ for(j=0;j<5;j++) printf("%c",c[i][j]); printf("\n"); } return 0; }C++ :
#include <stdio.h> int main() { char diamond[5][5] = { {' ', ' ', '*', ' ', ' '}, {' ', '*', ' ', '*', ' '}, {'*', ' ', ' ', ' ', '*'}, {' ', '*', ' ', '*', ' '}, {' ', ' ', '*', ' ', ' '}}; int i, j; for (i = 0;i < 5;i++) { for (j = 0;j < 5;j++) printf("%c", diamond[i][j]); puts(""); } return 0; }Pascal :
var s:string; begin s:=space(5); s[3]:='*'; writeln(s); s:=space(5); s[2]:='*'; s[4]:='*'; writeln(s); s:=space(5); s[1]:='*'; s[5]:='*'; writeln(s); s:=space(5); s[2]:='*'; s[4]:='*'; writeln(s); s:=space(5); s[3]:='*'; writeln(s); end.Java :
public class Main { public static void main(String[] args) { String str = ""+ " * \n"+ " * * \n"+ "* *\n"+ " * * \n" + " * \n" ; System.out.println(str); } }Python :
def f(a): b = ' ' * (3 - a) + '*' + ' ' * (a - 1) return b+b[0: 2][::-1] for i in range(1, 4): print f(i) for i in range(2, 0, -1): print f(i)
- 1
Information
- ID
- 17065
- Time
- 1000ms
- Memory
- 32MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By