C sharp - Crear un cuadrado con números

 
Vista:

Crear un cuadrado con números

Publicado por Jon (2 intervenciones) el 22/11/2020 23:41:37
Si pongo 4 y 4.
Este código me saca un rectángulo tipo :
112112
334334

Yo quiero que me saque un rectángulo tipo:
1122
3344

Muchas gracias de antemano.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
 
int main()
{
 int N=0;
 int M=0;
 int i = 0;
 int a = 0;
 int b = 0;
 do{
     printf("Introduce un numero N entre 1 y 20:\n");
     scanf("%d",&N);
 
     if(N < 1 || N > 20){
         printf("Error\n");
     }
 
 
 }while(N < 1 || N > 20);
 
 do{
    printf("Introduce un numero M entre 1 y 80:\n");
    scanf("%d",&M);
 
    if(M < 1 || M > 80){
        printf("Error\n");
    }
 
 
 }while(M < 1 || M > 80);
 
 
 
 for (i= 0; i < N/2; i++) {
    for (a = M/2; a < M; a++) {
    for (b = 0;b < M/2;b++){
            printf("1");
 
             }
 
    printf("2");
 
     }
     printf("\n");
 }
 for (i= 0; i < N/2; i++) {
    for (b = 0;b < M/2;b++) {
    for (a = M/2; a < M; a++){
            printf("3");
 
             }
 
    printf("4");
 
     }
     printf("\n");
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder