Program c segitiga bilangan ganjil

#include <stdio.h>
#include <windows.h>

#define ROWS 4
#define COLS 7

void DisplayBuffer(const int*, int, int);
void FillBuffer(int*, int, int);
void Delay(void);

int main(int argc, char *argv[]) {
int buffer[ROWS][COLS], rows = ROWS, cols = COLS;
FillBuffer((int*)buffer,rows,cols);
DisplayBuffer((int*)buffer,rows,cols);
system(“PAUSE”);
return 0;
}

void DisplayBuffer(const int* buffer, int rows, int cols) {
int row, col;
for(row = 0; row < rows; ++row) {
for(col = 0; col < cols; ++col) {
if(*(buffer+cols*row+col) == 0) {
printf(” “);
} else {
printf(“%d”,*(buffer+cols*row+col));
Delay();
}
}
printf(“\n”);
}
}

void FillBuffer(int* buffer, int rows, int cols) {
int angka = 1, row, col, kolom = rows-1, batas = rows;
for(row = 0; row < rows; ++row) {
for(col = 0; col < cols; ++col) {
*(buffer+cols*row+col) = 0;
}
} for(row = 0; row < rows; ++row) {
for(col = kolom; col < batas; ++col) {
*(buffer+cols*row+col) = angka;
}
angka+=2;
++batas;
–kolom;
}
}

void Delay(void) {
int i = 0;
while(i < 10000000) {
++i;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: