CARI Infonet

 Forgot password?
 Register

ADVERTISEMENT

View: 3230|Reply: 11

How to solve this question? using C language..

[Copy link]
Post time 24-7-2010 01:43 PM | Show all posts |Read mode
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

Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 24-7-2010 02:33 PM | Show all posts
takde yg boleh jawab ke?
Reply

Use magic Report

Post time 24-7-2010 02:46 PM | Show all posts
Pakai C++ boleh?
Reply

Use magic Report

 Author| Post time 24-7-2010 02:50 PM | Show all posts
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;
}
Reply

Use magic Report

Post time 24-7-2010 03:22 PM | Show all posts
OK siap...

  1. #include <iostream>

  2. using namespace std;

  3. int main()
  4. {
  5.     char ch;
  6.     int ord;

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

  9.     for (int j=0; j<=4; j++)
  10.     {
  11.         for (int i=4; i>=j; i--)
  12.         {
  13.             ord = static_cast<int>(ch) - i;
  14.             cout << static_cast<char>(ord);
  15.         }
  16.         cout << endl;
  17.     }

  18. return 0;
  19. }
Copy the Code

Rate

1

View Rating Log

Reply

Use magic Report

 Author| Post time 24-7-2010 03:54 PM | Show all posts
Reply 5# juwaini


thanks juwaini ...

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...   
Reply

Use magic Report

Follow Us
Post time 25-7-2010 12:44 PM | Show all posts
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.
Reply

Use magic Report

Post time 25-7-2010 01:03 PM | Show all posts
Post Last Edit by alien3d at 25-7-2010 13:21

jawapan  tu tak lengkap.
kalau php la
<?php

  1. <?php

  2. $request='N';
  3. $continue=0;
  4. foreach (range('Z', 'A') as $letter) {
  5.    //echo $letter;
  6.    if($letter == $request) {
  7.         $continue=1;
  8.    }
  9.    if($continue==1) {
  10.     $str.=$letter;
  11.    }
  12. }
  13.   $str_array =str_split($str);
  14.   $str_array = array_reverse($str_array);     
  15.   echo  implode('',$str_array);
  16. ?>
  17. ?>
Copy the Code

Rate

1

View Rating Log

Reply

Use magic Report


ADVERTISEMENT


Post time 25-7-2010 01:10 PM | Show all posts
way 1
1. create an array  contain 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.
Reply

Use magic Report

 Author| Post time 26-7-2010 11:21 AM | Show all posts
Reply 9# alien3d

ni soalan nak kiteorg jwb ke?
Reply

Use magic Report

Post time 26-7-2010 11:37 AM | Show all posts
Reply 10# LanzSlumber


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

Use magic Report

Post time 20-10-2010 01:23 AM | Show all posts
Reply 5# juwaini

ada bug.
kalo enter huruf selain e dia x dpt nak buat triangle...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CARI Infonet

28-4-2024 08:57 PM GMT+8 , Processed in 0.076418 second(s), 39 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list