Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call function diamond
27-10-2013, 07:44 PM,
Post: #1
call function diamond
knpe time run and pilih diamond.
shape dia xkluar eh?
shape lain ok.
ada ttinggal ape eh?
=.=.

Code:
#include<stdio.h> //header file


int main()
{
     int option,row,length,height,area;     //declaration
     int vertical_line(int l);              //declaration
     int perimeter;                         //declaration
     int rectangle(int h,int l);            //declaration
     int triangle(int h);                   //declaration
     int diamond(int h);                    //declaration

     option=0;

    while(option!=5)                                                //function body
    {
         printf("\n\t\tPlese select the options below.\n");
         printf("\t\t(1)-------->>Vertical Line\n");
         printf("\t\t(2)-------->>Rectangle\n");
         printf("\t\t(3)-------->>Triangle\n");
         printf("\t\t(4)-------->>Diamond\n");
         printf("\t\t(5)-------->>Exit\n\n");
         printf("Option selected :");
         scanf("%d",&option);


switch(option)
     {
     case(1):
         {
            do
            {
                printf("\nPlease enter the row of a vertical line. ");
                scanf("%d",&row);

                if(row==0)
                    {
                        break;
                    }
                perimeter = row;
                printf("\nPerimeter of the vertical line is %d\n", perimeter);
                printf("\nArea : Omit\n");
                vertical_line(row);
                printf("\nEnter 0 to back to the main page.\n");
            }

            while(row!=0);
            {
                break;
            }
         }


    case(2):
         {

             do
             {
                printf("\nPlease enter the height of a rectangle.");
                scanf("%d",&height);
                if(height==0)
                    {
                    break;
                    }
                printf("\nPlease enter the length of a rectangle.");
                scanf("%d", &length);
                area = length * height;
                perimeter = length+height+length+height;
                printf("\nArea of the rectangle is %d\n", area);
                printf("\nPerimeter of the rectangle is %d\n", perimeter);
                rectangle(height,length);

                printf("\nArea of rectangle = height x length\n");

                printf("\t\t= %d x %d",height,length);
                printf("\nEnter 0 to back to the main page.\n");
                return area;
                    }

                while(length!=0);
                break;
            }

    case(3):
         {
             do
             {
                printf("\n\nPlease enter the height of a triangle.");

                scanf("%d",&height);
                if(height==0)
                    {
                        break;
                    }
                triangle(height);

                printf("\nArea of triangle = height x height/2\n");
                printf("\t\t= (%d x %d)/2",height,height);
                area = 0.5*(height * height);
                perimeter = (length*height)*2;

                printf("\nArea of the triangle is =%d\n",area);
                printf("\nPerimeter of the triangle is =%d\n", perimeter);
                printf("\nEnter 0 to back to the main page.\n");
                return area;
                    }

            while(height!=0);
            break;
         }

    case(4):
         {
            do
             {
                printf("\nPlease enter the height of a diamond.");
                scanf("%d",&height);
                if(height==0)
                    {
                        break;
                    }



                printf("\nArea of diamond = height x height x 2\n");
                printf("\t\t=%d x %d x2",height,height);

                area = 2*(height * height);

                perimeter = (4*height);
                printf("\nArea of the diamond is=%d\n",area);
                printf("\nPerimeter of the diamond is=%d\n", perimeter);
                printf("(Enter 0 to back to the main page.)\n");
                return area;
                    }
            while(height!=0);
            break;
         }

case(5):
         {
             break;
         }
     default:
         {
             printf("\nBad input, quitting!\n");
         }
     }
     }


}



//Function to draw vertical line.
int vertical_line(int l)
    {
    int a;

    for(a=1; a<7; a++)
    {
        printf("%d\n", a);
    }
    
    return vertical_line;

    }

//Function to draw rectangle.
int rectangle(int w,int l)

{
  int p, q, r;
  for(p=5;p>=1;p--)
  {
    r = p;
    for(q=1;q<=5;q++)
    {
      if(r <= 5)
      {
        printf("%d",r);
      }
      else
      {
        printf("5");
      }
      r++;
    }
  printf("\n");
  }
return rectangle;
}

//Function to draw triangle.
   int triangle(int h)
{

int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>i;j--)
        {
          printf(" ");
        }
        for(j=1;j<=i;j++)
        {
          printf("%d ",j);
        }
        printf("\n");
    }

    return triangle;

//Function to draw diamond.
  int diamond(int h)

{
int num,r,c,sp;
num = 4;
for(r=1; r<=num; r++)
{
   for(sp=num-r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=r; c++)
       printf("%d",c);
   for(c=r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
}
for(r=1; r<=num; r++)
{
   for(sp=r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=(num-r); c++)
       printf("%d",c);
   for(c=num-r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
}

return diamond;




system("pause");
return 0;
}
}
Reply
27-10-2013, 07:58 PM, (This post was last modified: 27-10-2013, 08:56 PM by pers0nant.)
Post: #2
RE: call function diamond
(27-10-2013, 07:44 PM)troy Wrote: knpe time run and pilih diamond.
shape dia xkluar eh?
shape lain ok.
ada ttinggal ape eh?
=.=.

Code:
#include<stdio.h> //header file


int main()
{
     int option,row,length,height,area;     //declaration
     int vertical_line(int l);              //declaration
     int perimeter;                         //declaration
     int rectangle(int h,int l);            //declaration
     int triangle(int h);                   //declaration
     int diamond(int h);                    //declaration

     option=0;

    while(option!=5)                                                //function body
    {
         printf("\n\t\tPlese select the options below.\n");
         printf("\t\t(1)-------->>Vertical Line\n");
         printf("\t\t(2)-------->>Rectangle\n");
         printf("\t\t(3)-------->>Triangle\n");
         printf("\t\t(4)-------->>Diamond\n");
         printf("\t\t(5)-------->>Exit\n\n");
         printf("Option selected :");
         scanf("%d",&option);


switch(option)
     {
     case(1):
         {
            do
            {
                printf("\nPlease enter the row of a vertical line. ");
                scanf("%d",&row);

                if(row==0)
                    {
                        break;
                    }
                perimeter = row;
                printf("\nPerimeter of the vertical line is %d\n", perimeter);
                printf("\nArea : Omit\n");
                vertical_line(row);
                printf("\nEnter 0 to back to the main page.\n");
            }

            while(row!=0);
            {
                break;
            }
         }


    case(2):
         {

             do
             {
                printf("\nPlease enter the height of a rectangle.");
                scanf("%d",&height);
                if(height==0)
                    {
                    break;
                    }
                printf("\nPlease enter the length of a rectangle.");
                scanf("%d", &length);
                area = length * height;
                perimeter = length+height+length+height;
                printf("\nArea of the rectangle is %d\n", area);
                printf("\nPerimeter of the rectangle is %d\n", perimeter);
                rectangle(height,length);

                printf("\nArea of rectangle = height x length\n");

                printf("\t\t= %d x %d",height,length);
                printf("\nEnter 0 to back to the main page.\n");
                return area;
                    }

                while(length!=0);
                break;
            }

    case(3):
         {
             do
             {
                printf("\n\nPlease enter the height of a triangle.");

                scanf("%d",&height);
                if(height==0)
                    {
                        break;
                    }
                triangle(height);

                printf("\nArea of triangle = height x height/2\n");
                printf("\t\t= (%d x %d)/2",height,height);
                area = 0.5*(height * height);
                perimeter = (length*height)*2;

                printf("\nArea of the triangle is =%d\n",area);
                printf("\nPerimeter of the triangle is =%d\n", perimeter);
                printf("\nEnter 0 to back to the main page.\n");
                return area;
                    }

            while(height!=0);
            break;
         }

    case(4):
         {
            do
             {
                printf("\nPlease enter the height of a diamond.");
                scanf("%d",&height);
                if(height==0)
                    {
                        break;
                    }



                printf("\nArea of diamond = height x height x 2\n");
                printf("\t\t=%d x %d x2",height,height);

                area = 2*(height * height);

                perimeter = (4*height);
                printf("\nArea of the diamond is=%d\n",area);
                printf("\nPerimeter of the diamond is=%d\n", perimeter);
                printf("(Enter 0 to back to the main page.)\n");
                return area;
                    }
            while(height!=0);
            break;
         }

case(5):
         {
             break;
         }
     default:
         {
             printf("\nBad input, quitting!\n");
         }
     }
     }


}



//Function to draw vertical line.
int vertical_line(int l)
    {
    int a;

    for(a=1; a<7; a++)
    {
        printf("%d\n", a);
    }
    
    return vertical_line;

    }

//Function to draw rectangle.
int rectangle(int w,int l)

{
  int p, q, r;
  for(p=5;p>=1;p--)
  {
    r = p;
    for(q=1;q<=5;q++)
    {
      if(r <= 5)
      {
        printf("%d",r);
      }
      else
      {
        printf("5");
      }
      r++;
    }
  printf("\n");
  }
return rectangle;
}

//Function to draw triangle.
   int triangle(int h)
{

int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>i;j--)
        {
          printf(" ");
        }
        for(j=1;j<=i;j++)
        {
          printf("%d ",j);
        }
        printf("\n");
    }

    return triangle;

//Function to draw diamond.
  int diamond(int h)

{
int num,r,c,sp;
num = 4;
for(r=1; r<=num; r++)
{
   for(sp=num-r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=r; c++)
       printf("%d",c);
   for(c=r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
}
for(r=1; r<=num; r++)
{
   for(sp=r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=(num-r); c++)
       printf("%d",c);
   for(c=num-r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
}

return diamond;




system("pause");
return 0;
}
}

ko x panggil pon function diamond() tuh. btw, bracketing hancuss Fuck That Shit
Reply
27-10-2013, 08:18 PM, (This post was last modified: 27-10-2013, 08:19 PM by jalil.)
Post: #3
RE: call function diamond
peningnya code anda, nape tak susun dulu? baru senang orang nak faham.


dan untuk setiap function, kenapa perlu declarekan sebagai int? sebab function tu hanya untuk print out saje, tak return apa-apa integer value. Pakai void.
Reply
27-10-2013, 09:07 PM,
Post: #4
RE: call function diamond
question:

- return area tu untuk ape?
- variable yang ko pass tuh memang x guna dalam function ek?
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  draw diamond troy 6 790 26-10-2013, 02:27 AM
Last Post: fatah
  [SOLVED] tidak ada error tetapi function tidak papar hard3 1 403 21-09-2013, 09:22 AM
Last Post: hard3
  [ASK]Function [SOLVED] - Credit to Rempah Xantium 5 557 20-05-2013, 09:00 PM
Last Post: Xantium
  Having 2 friends function in a class muhammadjaziem 2 333 20-03-2013, 01:45 AM
Last Post: Cybercrookz
  [help]tolong delete function rosak T.T Timon 0 488 31-05-2012, 03:10 AM
Last Post: Timon
  [help] nak wat approve dengan disapprove function SMAS Timon 3 981 23-05-2012, 06:40 PM
Last Post: Timon
  [help]c++ function execute if else statement output pron3t 10 1,112 16-03-2012, 12:34 PM
Last Post: pron3t
  [ask]weak about function pron3t 6 966 11-02-2012, 03:20 AM
Last Post: otai_g
  [help] New & delete function in c++ th3phantom 2 661 20-01-2012, 11:18 PM
Last Post: th3phantom
  [C] md5 function Ahlspiess 23 7,840 04-10-2010, 12:13 AM
Last Post: fatah

Forum Jump: