Pattern Codes
Pattern Codes
#include <stdio.h>
#include <time.h>
int main() {
time_t tm;
time(&tm);
printf("Current Date/Time = %s\n\n\n", ctime(&tm));
int i, j, num = 1;
return 0;
}
Output:
1
23
456
7 8 9 10
Pattern 2:
#include <stdio.h>
#include <time.h>
int main() {
time_t tm;
time(&tm);
printf("Current Date/Time = %s\n\n\n", ctime(&tm));
if (i != n) {
for (j = i; j >= 1; j--) {
printf("%d", j);
}
} else {
for (j = i - 1; j >= 1; j--) {
printf("%d", j);
}
}
printf("\n");
}
return 0;
}
Output:
1 1
12 21
123 321
1234321
Pattern 3:
#include <stdio.h>
#include <time.h>
int main() {
time_t tm;
time(&tm);
printf("Current Date/Time = %s\n\n\n", ctime(&tm));
int i, j, n = 4;
return 0;
}
Output:
1234321
12321
121
1
Pattern 4:
#include <stdio.h>
#include <time.h>
int main() {
time_t tm;
time(&tm);
printf("Current Date/Time = %s\n\n\n", ctime(&tm));
// Print decreasing numbers if it's not the first row (no spaces in the top row)
if (i != 1) {
for (j = n - i + 1; j >= 1; j--) {
printf("%d", j);
}
}
printf("\n");
}
// Print decreasing numbers if it's not the first row of the lower part
if (i != 1) {
for (j = n - i + 1; j >= 1; j--) {
printf("%d", j);
}
}
printf("\n");
}
return 0;
}
Output:
1234321
123 321
12 21
1 1
12 21
123 321
1234321