1588, 1/80 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   lackhole
   Penguins.png (18.4 KB), Download : 14     [¿À¸¥ÂÊ ¹öÆ° ´­·¯ ´Ù¿î ¹Þ±â]
   [Æß]C Language (swap)

http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=8159 [º¹»ç]



c¾ð¾î swap¿¹Á¦

a ¿¡´Ù 1À» ÀÔ·ÂÇÏ°í b¿¡´Ù 2¸¦ ÀÔ·ÂÇÏ°í a¿ÍbÀÇ °ªÀ» ¹Ù²Ù´Â ¿¹Á¦¸¦ ¸¸µé¶ó°í ÇÑ´Ù¸é c¾ð¾î¸¦ ÃʹÝÀ¸·Î Á¢ÇϽô ºÐµéÀº ¾Æ·¡¿Í °°ÀÌ ÀÛ¼ºÇÒ¼öµµ ÀÖ´Ù

#include <Stdio.h>

int main(void)
{
        int a , b;
        
        printf("a :");
        scanf("%d",&a); //1·Î ÀÔ·ÂÇÑ°æ¿ì
        
        printf("b :");
        scanf("%d",&b); //2·Î ÀÔ·ÂÇÑ°æ¿ì
        
        b = a;  
        a = b;  
        
        printf("a : %d\nb : %d\n",a , b);
        
        return 0;
}
c¾ð¾î¸¦ ÃʹÝÀ¸·Î Á¢ÇϽŠºÐÀº ÀÌ·¸°Ô ÀÛ¼ºÇÒ¼öµµ ÀÖ½À´Ï´Ù.

ÇÏÁö¸¸ ÀÌ·¸°Ô ÀÛ¼ºÇϸé
b=a;
a=b;
ºÎºÐ¿¡¼­ °ª¼Õ½ÇÀÌ ÀϾ´Ï´Ù.
ÀÏ´Ü aÀÇ °ªÀ» b¿¡´Ù ³Ö¾ú½À´Ï´Ù.c¾ð¾î´Â À§¿¡¼­ ¾Æ·¡·Î Àб⠶§¹®¿¡
a=b;¿¡¼­ a°ª¿¡´Ù b¸¦ ³ÖÁö¸¸  À§¿¡¼­ bÀÇ °ªÀÌ a·Î ¹Ù²ï »óÅ·ΠµÇ±â¶§¹®¿¡ µÑ´Ù aÀÇ °ª°ú µ¿ÀÏÇØÁø´Ù´Â ¿À·ù°¡ ÀÖ½À´Ï´Ù.
±×·¡¼­ swapÀº ¾Æ·¡¿Í °°Àº ÄÚµå

#include <Stdio.h>

int main(void)
{
        int a , b;
        int tmp = 0; //temporay
        
        printf("a :");
        scanf("%d",&a); //1·Î ÀÔ·ÂÇÑ°æ¿ì
        
        printf("b :");
        scanf("%d",&b); //2·Î ÀÔ·ÂÇÑ °æ¿ì
        
        tmp = b;  //b°ª ¹Ì¸® ÀúÀå
        b = a;  //b°ªÀÌ a·Î ¹Ù²ñ  //swap
        a = tmp;  //aÀÇ °ªÀº tmpÀÇ ÀúÀåµÈ bÀÇ °ª
        
        printf("a : %d\nb : %d\n",a , b);
        
        return 0;
}

ÀÌ·¸°Ô bÀÇ °ªÀ» ¹Ì¸® tmp¶ó´Â º¯¼öÀÇ ÀúÀåÀ»ÇØÁÖ°í
a = tmp;·Î ÀúÀåµÈ bÀÇ °ªÀ» °¡Á®¿É´Ï´Ù'


  Hit : 7900     Date : 2015/10/17 07:38



    
wsj7178 ÀÌ°É ÀÌ¿ëÇؼ­ ÇÔ¼öµµ ¸¸µé¼ö ÀÖÁÒ
void swap(int *x, int *y)
{
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
2015/11/29  
     [°øÁö] °­Á¸¦ ¿Ã¸®½Ç ¶§´Â ¸»¸Ó¸®¸¦ ´Þ¾ÆÁÖ¼¼¿ä^¤Ñ^ [29] ¸Û¸Û 02/27 19238
1587   netdiscover ÆÄÀ̽ãÀ¸·Î ±¸ÇöÇϱ⠠   ÇØÅ·ÀßÇÏ°í½Í´Ù
08/13 162
1586   ÆÄÀ̽ãÀ» ÀÌ¿ëÇÑ ½ÉÇà À¥ Å©·Ñ·¯     ÇØÅ·ÀßÇÏ°í½Í´Ù
08/13 130
1585   ÆÄÀ̽ã random¸ðµâÀ» ÀÌ¿ëÇÑ ¼ýÀÚ¸ÂÃ߱⠰ÔÀÓ ±¸Çö     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/30 646
1584   ÆÄÀ̽ã äÆà ÇÁ·Î±×·¥ ±¸Çö     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/28 556
1583   ÆÄÀ̽㠼ÒÄÏ ÇÁ·Î±×·¡¹ÖÀÇ ±âÃÊ     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/26 579
1582   ¸®´ª½º À¥ ·Î±× ºÐ¼®     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/20 442
1581   ¸®´ª½º/À©µµ¿ì º¸¾È Àåºñ ·Î±×     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/20 543
1580   °í¼ö´ÔµéÀÇ µµ¿òÀ» ¹Þ°í ½Í½À´Ï´Ù     vbnm111
02/11 692
1579   ¸®´ª½º Ä¿³Î 2.6 ¹öÀü ÀÌÈÄÀÇ LKM     jdo
07/25 1211
1578   ½©ÄÚµå ¸ðÀ½     ÇØÅ·ÀßÇÏ°í½Í´Ù
01/15 2052
1577   Call by value VS Call by Reference     ÇØÅ·ÀßÇÏ°í½Í´Ù
01/15 1401
1576   (²Ä¼ö) L.O.B Çѹ濡 Ŭ¸®¾îÇϱâ[2]     ÇØÅ·ÀßÇÏ°í½Í´Ù
01/14 1798
1575   towelroot.c (zip) ÄÚ¸àÆÃ.[1]     scube
08/18 4331
1574   levitator.c (¾Èµå·ÎÀÌµå ·çÆÃ) °ø°Ý ºÐ¼® ¼Ò½º ÄÚµå °øÀ¯.[4]     scube
08/17 4178
1573   ¹«·á Á¤º¸º¸¾È ±â¼úÀÎÀç ¾ç¼º °úÁ¤ ±³À°»ý ¸ðÁý     chanjung111
06/17 5044
1572   K-Shield ÁִϾî 5±â ¸ðÁý     lrtk
06/17 4745
1571   [ÆÁ] ÆÄÀ̽ã 2¼Ò½º¸¦ 3À¸·Î º¯°æÇØÁÖ´Â »çÀÌÆ®[3]     ÇѽÂÀç
05/13 4428
1570   ±¸±Û ¹é¸µÅ© ÀÛ¾÷ Áú¹®¿ä     wkatnxka
03/30 3831
1569   [ÆÁ] ¿ìºÐÅõ ¹Ì·¯¸µ¼­¹ö     ÇѽÂÀç
03/09 4555
1 [2][3][4][5][6][7][8][9][10]..[80]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org