#include <stdio.h> // Include "stdio.h" (C library to perform Input/Output operations)
#include <stdlib.h> // Include "stdlib.h" (C Standard General Utilities Library)
#define SIZE 50 // Define SIZE to 50, basically seaches the file for the word SIZE and replaces it with 50, this is done before the projekt is being compiled, simply by the precompiler
#define pi 3.14 // Same as above, just with 3.14 everytime "pi" occurs.
void pusha(int i); // Function Prototype
int pop(void); // Function Prototype
void sorta(int stacka[SIZE],int numbers); // Function Prototype
int *pointer, stacka[SIZE],numbers; // Create a pointer, an array and a var
int main(void)
{
int value,num,num2,num3,num4,array[5],num6,num7,num8; // Make a lot of vars
float num5,num9; // And a couple of floats
num=0; // Set the var num=0
pointer = stacka; // Make the global pointer point to the global stack
printf("************************************************\n"); // Output to screen
printf("----------------PROJECT-------------------------"); // Output to screen
printf("\nYOU SHOULD INPUT INTEGERS;\nTHEIR TOTAL NUMBER SHOULD BE DIVISIBLE BY THREE\n"); // Output to screen
printf("\nenter the number of integers you want to input::"); // Output to screen
scanf("%d",&numbers); // Scan for input, and write the input to the variable "numbers"
while((numbers%3)!=0 ||numbers==0 ) // While "numbers" isn't zero, and "numbers" is dividable with 3, then run the next lines. Untill the entered number is correct.
{
printf("the number is not divisible by 3\n");
printf("TRY AGAIN;\nenter the number again::");
scanf("%d",&numbers);
}
do { // Start a Do-While loop
printf("\nEnter the values consequitively: "); // Output to screen
scanf("%d", &value); // Scan for input, and write the input to the variable "value"
if(value != 0) // If value is different from zero, then run the following:
{
pusha(value); // Call the function Pusha and send it the var "value".
}
num++; // Indent the variable "num".
}
while(num<=(numbers-1)); // Run the Do-While loop, while num is less or equal to (numbers-1)
printf("\n\n\nelements in the stack are::"); // Output to screen
for(num=0;num<=(numbers-1);num++) // Run for loop for output, to output numbers
{
printf(" %d",stacka[num]); // Output to screen
}
printf("\n\nlets now sort it\n"); // Output to screen
printf("\npress 1 to sort it::"); // Output to screen
scanf ("%d",&num3); // Scan for input, and write the input to the variable "num3"
if(num3==1) // If num3 equals 1, then run the following, if it dosn't exit the program.
{
sorta(stacka,numbers);
}
else
{
return 0; // Exit the program
}
for(num6=0;num6<=((numbers/3)-1);num6++)
{printf("\n\nwe pop the elements in 3's\n");
for(num=0;num<=2;num++)
{ array[num]= pop();
printf(" %d",array[num]);
}
num2= array[0]*array[1];
num7=2*(array[0]+array[1]);
if(array[0]==array[1])
{
printf("\n\nthe first 2 elements form sides of a square whose area is %d",num2);
printf("\nthe perimeter of this square is %d::",num7);
}
else
{printf("\n\nthe first 2 elements form sides of a rectangle whose area is %d",num2);
printf("\nthe perimeter of this rectangle is %d::",num7);
}
num4=array[2]*array[2];
num5=num4*pi;
num8=2*array[2];
num9=num8*pi;
printf("\n\n\nthe the 3rd element forms the radius of a circle whose area is %f",num5);
printf("\nthe perimeter of this circle is %f::\n",num9);
}
printf("\n\n\n****************END OF PROGRAM*******************\n\n");
}
void pusha(int i) // The pusha Function
{
*pointer=i; // Write "i" (value) to the pointer
pointer++; // Indent the pointer
}
void sort(int stacka[SIZE],int numbers)
{
int num,t,number;
for (number=0;number<=(numbers-1);number++)
for(num=0;num<=(numbers-1);num++)
{
if (stacka[num]>stacka[num+1])
{ t=stacka[num];
stacka[num]=stacka[num+1];
stacka[num+1]=t;
}}
printf("\nthe sorted array is::");
for(num=1;num<=numbers;num++)
{
printf(" %d",stacka[num]);
}}
int pop()
{int m;
m=*pointer;
pointer--;
return m;
}