Anda di halaman 1dari 14

KWADRAT O N BOKACH

#include<stdio.h>
int main(){
int side, i, j;
printf("Enter side of square\n");
scanf("%d", &side);
/* Row iterator for loop */
for(i = 0; i < side; i++){
/* Column iterator for loop */
for(j = 0; j < side; j++){
printf("*");
}
printf("\n");
}
return 0;
}
EKEFKT DZIALANIA Enter side of square
5
*****
*****
*****
*****
*****
=======================================================
TRJKT
#include<stdio.h>
#include<conio.h>
int main() {
int i,j,rows;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for(i = 1; i <= rows; i++) {
/* Prints one row of triangle */
for(j = 1; j <= i; ++j) {
printf("* ");
}
/* move to next row */
printf("\n");
}
getch();
return 0;
}
Output
Enter the number of rows
6
*
* *
* * *
* * * *
* * * * *
* * * * * *

========================================================
TRJKT
#include<stdio.h>
int main() {
int i,j,rows;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for(i = rows; i > 0; i--) {
/* Prints one row of triangle */
for(j = i; j > 0; j--) {
printf("* ");
}
/* move to next row */
printf("\n");
}
return 0;
}
Output
Enter the number of rows
6
* * * * * *
* * * * *
* * * *
* * *
* *
*
==========================================================
OBRYS KWADRATU
#include<stdio.h>
int main(){
int side, i, j;
printf("Enter side of square\n");
scanf("%d", &side);
/* Row iterator for loop */
for(i = 0; i < side; i++){
/* Column iterator for loop */
for(j = 0; j < side; j++){
/* Check if currely position is a boundary position */
if(i==0 || i==side-1 || j==0 || j==side-1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
Enter side of square
5

*****
* *
* *
* *
*****
====================================================================
OBRYS PROSTOK
#include<stdio.h>
int main(){
int rows, cols , i, j;
printf("Enter rows and columns of rectangle\n");
scanf("%d %d", &rows, &cols);
/* Row iterator for loop */
for(i = 0; i < rows; i++){
/* Column iterator for loop */
for(j = 0; j < cols; j++){
/* Check if currely position is a boundary position */
if(i==0 || i==rows-1 || j==0 || j==cols-1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
Enter rows and columns of rectangle
4 12
************
*
*
*
*
************
====================================================================
ROMB
#include <stdio.h>
int main() {
int i,j, rows;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for(i = 1; i <= rows; i++) {
/* Print spaces before stars in a row */
for(j=i; j<rows; j++) {
printf(" ");
}
/* Print rows stars after spaces in a row */
for(j = 1; j <= rows; j++) {
printf("*");

}
/* jump to next row */
printf("\n");
}
return 0;
}
Output
Enter the number of rows
6
******
******
******
******
******
******
==========================================================================
PIRAMIDA NA CZUBKU
#include<stdio.h>
int main() {
int i, space, rows, star;
printf("Enter the number of rows\n");
scanf("%d",&rows);
for(i = rows;i >= 1; i--) {
/* Printing spaces */
for(space = 0; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
star = 0;
while(star != (2*i - 1)) {
printf("*");
star++;
}
printf("\n");
}
return 0;
}
Output
Enter the number of rows
5
*********
*******
*****
***
*
==============================================================
PIRAMIDA NA PODSTAWIE
#include<stdio.h>
int main() {
int i, space, rows, star=0;

printf("Enter the number of rows\n");


scanf("%d",&rows);
/* printing one row in every iteration */
for(i = 1; i <= rows; i++) {
/* Printing spaces */
for(space = 1; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
printf("*");
star++;;
}
star=0;
/* move to next row */
printf("\n");
}
return 0;
}
Output
Enter the number of rows
6
*
***
*****
*******
*********
***********
========================================================================
DIAMOND
#include<stdio.h>
int main() {
int i, space, rows=7, star=0;
/* Printing upper triangle */
for(i = 1; i <= rows; i++) {
/* Printing spaces */
for(space = 1; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
printf("*");
star++;;
}
star=0;
/* move to next row */
printf("\n");
}
rows--;
/* Printing lower triangle */
for(i = rows;i >= 1; i--) {
/* Printing spaces */
for(space = 0; space <= rows-i; space++) {
printf(" ");

}
/* Printing stars */
star = 0;
while(star != (2*i - 1)) {
printf("*");
star++;
}
printf("\n");
}
return 0;
}
Output
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
============================================================================
DIOAMOND OBWDKA
#include<stdio.h>
int main() {
int i, space, rows=7, star=0;
/* Printing upper triangle */
for(i = 1; i <= rows; i++) {
/* Printing spaces */
for(space = 1; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
if(star == 0 or star==2*i-2)
printf("*");
else
printf(" ");
star++;
}
star=0;
/* move to next row */
printf("\n");
}
rows--;
/* Printing lower triangle */
for(i = rows;i >= 1; i--) {
/* Printing spaces */
for(space = 0; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
star = 0;

while(star != (2*i - 1)) {


if(star == 0 or star==2*i-2)
printf("*");
else
printf(" ");
star++;
}
printf("\n");
}
return 0;
}
Output
*
* *
* *
*
*
*
*
*
*
*
*
*
*
* *
* *
*
====================================================================
DOMEK
#include<stdio.h>
int main() {
int i, j, space, rows=8, star=0;
/* Printing upper triangle */
for(i = 1; i <= rows; i++) {
if(i <= 5){
/* Printing upper triangle */
for(space = 1; space <= 5-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
printf("*");
star++;;
}
star=0;
/* move to next row */
printf("\n");
} else {
/* Printing bottom walls of huts */
for(j = 0; j < 9; j++){
if((int)(j/3) == 1)
printf(" ");
else
printf("*");
}
printf("\n");
}
}
return 0;

}
Output
*
***
*****
*******
*********
*** ***
*** ***
*** ***
=================================================================
SERCE
#include <stdio.h>
int main() {
int i,j, rows;
printf("Enter the number of rows\n");
scanf("%d", &rows);
/* printing top semi circular shapes of heart */
for(i = rows/2; i <= rows; i+=2){
/* Printing Spaces */
for(j = 1; j < rows-i; j+=2) {
printf(" ");
}
/* printing stars for left semi circle */
for(j = 1; j <= i; j++){
printf("*");
}
/* Printing Spaces */
for(j = 1; j <= rows-i; j++){
printf(" ");
}
/* printing stars for right semi circle */
for(j = 1; j <= i; j++){
printf("*");
}
/* move to next row */
printf("\n");
}
/* printing inverted start pyramid */
for(i = rows; i >= 1; i--){
for(j = i; j < rows; j++){
printf(" ");
}
for(j = 1; j <= (i*2)-1; j++){
printf("*");
}
/* move to next row */
printf("\n");
}
return 0;
}
Output
Enter the number of rows
7

** **
**** ****
*********
*******
*****
***
*
==========================================================================
PIRAMIDA OBWDKA
#include<stdio.h>
int main() {
int i, space, rows, star=0;
printf("Enter the number of rows\n");
scanf("%d",&rows);
/* printing one row in every iteration */
for(i = 1; i < rows; i++) {
/* Printing spaces */
for(space = 1; space <= rows-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
if(star==0 || star==2*i-2)
printf("*");
else
printf(" ");
star++;;
}
star=0;
/* move to next row */
printf("\n");
}
/* print last row */
for(i=0; i<2*rows-1; i++){
printf("*");
}
return 0;
}
Output
Enter the number of rows
6
*
* *
* *
*
*
*
*
***********
============================================================================
LICZBY NATURALNE TROJKAT
#include<stdio.h>
int main() {
int i, j, rows;

int count = 1;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", count);
count++;
}
printf("\n");
}
return(0);
}
Output
Enter the number of rows
4
1
2 3
4 5 6
7 8 9 10
========================================================================
CYFERKIII
#include<stdio.h>
int main() {
int i, j, rows, count=0;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 1; i <= 2*rows; i=i+2) {
for (j = 1; j <= i; j++) {
printf("%c", 'A'+count);
if(j <= i/2)
count++;
else
count--;
}
count = 0;
printf("\n");
}
return(0);
}
Output
Enter the number of rows
5
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
===========================================================================
LICZBY W RZEDACH
#include<stdio.h>

int main() {
int i, j, rows;
int count = 1;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", i);
}
printf("\n");
}
return(0);
}
Output
Enter the number of rows
5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
================================================================================
=
TROJKAT Z LICZB PIERWSZYCH
#include<stdio.h>
int isPrimeNumber(int num);
int main() {
int i, j, rows;
int counter = 2;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
/* Try to find next prime number by
incrementing counter and testing it for primality */
while(!isPrimeNumber(counter)){
counter++;
}
printf("%d ", counter);
counter++;
}
printf("\n");
}
return(0);
}
int isPrimeNumber(int num) {
int i, isPrime = 1;
for (i = 2; i <= (num/2); i++) {
if (num % i == 0){
isPrime = 0;
break;
}

}
if (isPrime==1 || num==2)
return 1;
else
return 0;
}
Output
Enter the number of rows
4
2
3 5
7 11 13
17 19 23 29
=========================================================================
TROJKAT BINARNY
#include<stdio.h>
int main() {
int i, j, rows;
int count = 1;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", count);
count = !count;
}
count = i % 2;
printf("\n");
}
return(0);
}
Output
Enter the number of rows
5
1
1 0
0 1 0
1 0 1 0
0 1 0 1 0
============================================================================
PROSTOKAT BINARNY
#include<stdio.h>
int main(){
int rows, cols , i, j;
printf("Enter rows and columns of rectangle\n");
scanf("%d %d", &rows, &cols);
/* Row iterator for loop */
for(i = 0; i < rows; i++){
/* Column iterator for loop */
for(j = 0; j < cols; j++){
/* Check if currely position is a boundary position */

if(i==0 || i==rows-1 || j==0 || j==cols-1)


printf("0");
else
printf("1");
}
printf("\n");
}
return 0;
}
Output
Enter rows and columns of rectangle
4 7
0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
=============================================================
CUDA
#include<stdio.h>
int main() {
int i, j, rows;
int count = 1;
printf("Enter the number of rows\n");
scanf("%d", &rows);
for (i = 0; i < rows; i++) {
for (j = 0; j <= i; j++) {
printf("%d ", i*j);
}
printf("\n");
}
return(0);
}
Output
Enter the number of rows
6
0
0 1
0 2 4
0 3 6 9
0 4 8 12 16
0 5 10 15 20 25
======================================================
TABLICZKA MNOZENIA
#include <stdio.h>
int main()
{
int i, j;
int range = 10;
printf("%5c",' ');
for (i = 1; i <= range; i++)

printf("%5d", i);
for (i = 1; i <= range; i++)
{
printf("\n%5d", i);
for (j = 1; j <= range; j++)
{
printf("%5d", j*i);
}
}
}
===========================================================
ODWRACANIE KOLEJNOSCI TABLICY
#include <stdio.h>
int main()
{
int i, j;
int range = 10;
printf("%5c",' ');
for (i = 1; i <= range; i++)
printf("%5d", i);
for (i = 1; i <= range; i++)
{
printf("\n%5d", i);
for (j = 1; j <= range; j++)
{
printf("%5d", j*i);
}
}
}

Anda mungkin juga menyukai