LanzSlumber Publish time 24-7-2010 01:43 PM

How to solve this question? using C language..

Write a simple program where the input is a letter of the alphabet and the output is an upside down triangle as shown below:

input : E
output : ABCDE
             ABCD
             ABC
             AB
             A

:C:C

LanzSlumber Publish time 24-7-2010 02:33 PM

takde yg boleh jawab ke?:'(

juwaini Publish time 24-7-2010 02:46 PM

Pakai C++ boleh?

LanzSlumber Publish time 24-7-2010 02:50 PM

ok boleh... sy dah wat tp tak jadi...

ni cth yg saya wat, tp tak jadi..

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main ()
{
    char E;
   
    printf ( "Enter capital 'E': " );
    scanf ( "%c", &E );
   
    for (int c = 5; c > 0; c -- )
    {
      for ( int d = 1; d <= c; d ++ )
      {
            printf ("%c", ++E );
      }
      printf ( "\n" );
    }
   
    printf ( "\n\n" );
   
    system ( "pause" );
   
    return 0;
}

juwaini Publish time 24-7-2010 03:22 PM

OK siap...
#include <iostream>

using namespace std;

int main()
{
    char ch;
    int ord;

    cout << "Please enter 'E': ";
    cin >> ch;

    for (int j=0; j<=4; j++)
    {
      for (int i=4; i>=j; i--)
      {
          ord = static_cast<int>(ch) - i;
            cout << static_cast<char>(ord);
      }
      cout << endl;
    }

return 0;
}

LanzSlumber Publish time 24-7-2010 03:54 PM

Reply 5# juwaini


thanks juwaini ... {:1_152:}

your answer has give me this idea...

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main ()
{
    char E;
   
    printf ("Enter capital 'E': ");
    scanf ("%c", &E );
   
    for (int c = 0; c < 5; c ++ )
    {
      for (int d = 4; d >= c; d -- )
      {
            printf ("%c", E - d );
      }
      printf ("\n\n" );
    }
   
    system ("pause" );
   
    return 0;
}

am just improvise it...    :D

juwaini Publish time 25-7-2010 12:44 PM

Sintaks tak penting. Yang penting paham dia punya logik je...

BTW, kalau ko pure C programmer, line "using namespace std" tu tak perlu lagi dah... Yang tu cuma untuk C++ je.

alien3d Publish time 25-7-2010 01:03 PM

Post Last Edit by alien3d at 25-7-2010 13:21

jawapantu tak lengkap.
kalau php la
<?php
<?php

$request='N';
$continue=0;
foreach (range('Z', 'A') as $letter) {
   //echo $letter;
   if($letter == $request) {
      $continue=1;
   }
   if($continue==1) {
    $str.=$letter;
   }
}
$str_array =str_split($str);
$str_array = array_reverse($str_array);   
echoimplode('',$str_array);
?>
?>

alien3d Publish time 25-7-2010 01:10 PM

way 1
1. create an arraycontain A to Z
2.loop the array until X
3.break the loop .
4.print reverse order of the val
way 2
1.create an array contain Z to A
2. loop the array until X
3.Create a variable which can catch value after found event
4.print value
** maaf tak sesuai aku tulis dalam bahasa melayu.

LanzSlumber Publish time 26-7-2010 11:21 AM

Reply 9# alien3d

ni soalan nak kiteorg jwb ke?

alien3d Publish time 26-7-2010 11:37 AM

Reply 10# LanzSlumber


    itu namanya pseudo code.... bukan soalan.Sorry wa no degree people.

otai_g Publish time 20-10-2010 01:23 AM

Reply 5# juwaini

ada bug.
kalo enter huruf selain e dia x dpt nak buat triangle...
Pages: [1]
View full version: How to solve this question? using C language..


ADVERTISEMENT