Thread: Is this right?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Darn, doesn't seem to apply to C++, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Apr 2008
    Posts
    83
    Quote Originally Posted by Beachblue View Post
    Here's the question: Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

    Code:
    #include<stdio.h>
    
    main()
    {
       int c,d;
    
       printf( "\nEnter c value:" );
       scanf( "%d", &c );
       printf( "\nEnter d value:" );
       scanf( "%d", &d );
    
       printf("\nc=%d", d);
       printf( "\nd=%d", c);
     
       getchar();
       getchar();
    }
    I think my program interchanges the values of 2 variables... Is that the same as interchanging the 'contents of 2 locations'?
    This is your code
    [code]
    #include "stdio.h"
    void swap(int *, int *);
    int main()
    {
    int c,d;

    printf( "\nEnter c value:" );
    scanf( "%d", &c );
    printf( "\nEnter d value:" );
    scanf( "%d", &d );
    swap(&c, &d);
    printf("\nc=%d", c);
    printf( "\nd=%d", d);
    return 0;
    }

    void swap(int *p, int *q)
    {
    int temp;
    temp=*p;
    *p=*q;
    *q=temp;

    }
    [\code]

  3. #18
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Actually, I think, [\code] should be [/code] here.

Popular pages Recent additions subscribe to a feed