Switch Case, Menu, Parallelogram, Artan ve Azalan Yıldız Piramitleri

mustaphos

MB Üyesi
Kayıt
14 Eylül 2015
Mesajlar
35
Tepkiler
8
Yaş
28
Meslek
Öğrenci
Üniv
Anadolu University
Merhaba.
Bu C programı öncelikle bir değer ister. Değer 1 ile 3 arasında oluncaya kadar da değer sormaya devam eder.
1 ise parallelogram üretir. (Sonra bir değer daha istiyor.)
2 ise artan yıldız piramidi
3 ise azalan yıldız piramidi
İyi çalışmalar.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

int firstinteger;
int parallelogram;
int row;
int column;
int space;
int firstpoint;
int secondpoint;
int counter;
firstinteger = 0;/* firstinteger is defined as zero because of the while loop starts correctly */
parallelogram = 0;/* parallelogram is defined as zero because of the while loop starts correctly */

void main ()
{
while(firstinteger < 1 || firstinteger > 3) /* Testing firstinteger between [1,3]. If it is not in that domain start while loop. If it is in that domain go to switch case. */
{
printf("Please write an integer between one and three : ");
scanf("%d",&firstinteger);
printf("\n");
}

switch (firstinteger) /* Testing firstinteger for being 1,2 or 3. */
{
case 1 : /* If firstinteger is 1, start the parallelogram section. */
{
while ( parallelogram <= 0 ) /* If parallelogram integer less than or equal to 0, start while loop.*/
{
printf("Please write an integer more than zero : ");
scanf("%d",&parallelogram);
printf("\n");
}
row=0;
while ( row < parallelogram) /* While loop for drawing rows. */
{
space = 0;
while ( space < row ) /* While loop for spaces on the left side. */
{
printf("");
space++;
}
column = 0;
while ( column < parallelogram ) /* While loop for drawing columns. */
{
printf("*");
column++;
}
printf("\n");
printf("\n");
printf("\n");
printf("\n");

row++;

}

}
break; /* End of statement */

case 2 : /* If firstinteger is 2, start the increasing stars pyramide. */
{
while ( firstpoint >= secondpoint || firstpoint <= 0 || secondpoint <= 0 ) /* firstpoint must be less than secondpoint and firstpoint and secondpoint must be more than zero. */
{
printf("Second integer must be more than first integer . \n");
printf("\n");
printf("Please write the first integer more than zero : ");
scanf("%d",&firstpoint);
printf("\n");
printf("Please write the second integer more than zero : ");
scanf("%d",&secondpoint);
printf("\n");
}
while ( firstpoint <= secondpoint ) /* Draw the rows. */
{
counter = 0;
while ( counter < firstpoint) /* Draw the stars columns. */
{
printf("*");
counter++
}
printf("\n");
firstpoint++;

}
}
break; /* End of statement */

case 3 : /* If firstinteger is 3, start the decreasing stars pyramide. */
{
while ( firstpoint <= secondpoint || firstpoint <= 0 || secondpoint <= 0 ) /* firstpoint must be more than secondpoint and firstpoint and secondpoint must be more than zero. */
{
printf("First integer must be more than second integer . \n");
printf("\n");
printf("Please write the first integer more than zero : ");
scanf("%d",&firstpoint);
printf("\n");
printf("Please write the second integer more than zero : ");
scanf("%d",&secondpoint);
printf("\n");
}
while ( firstpoint >= secondpoint ) /* Draw the rows. */
{
counter = 0;
while ( counter < firstpoint ) /* Draw the stars columns. */
{
printf("*");
counter++;
}
printf("\n");
firstpoint--;
}
}
break; /* End of statement */

}
getch();
}
 
Yukarı Alt