Results 1 to 4 of 4

Thread: Array correction

  1. #1
    Join Date
    Nov 2009
    Posts
    446

    Array correction

    Hi
    Please help me. I have done these program please correct where is the error. I tried to find out but I have not yet got the correct error. This is the code to find union of two arrays.
    Code:
    main()
    {
    int x[5]={1,3,4,6,8},b[5]={2,4,5,6,10},i,d,k,c[10];
    for(i=0;i<5;i++)
    {
    for(d=0;d<5;d++)
    {
    if(x[i]!=b[d])
    {
    c[k]=x[i];
    k++;
    }
    else
    c[k]!=x[i];
    }
    }
    strcat(b,c);
    printf("%s",b);
    }
    This is the code to find intersection of two arrays
    Code:
    main()
    {
    int x[5]={1,3,4,6,8},b[5]={2,4,5,6,10},i,d,k,c[10];
    for(i=0;i<5;i++)
    {
    for(d=0;d<5;d++)
    {
    if(x[i]==b[d])
    {
    c[k]=x[i];
    k++;
    }
    else
    c[k]!=x[i];
    }
    }
    printf("%s",b);
    }
    Please check were is the error. Thanks in advance.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Array correction

    Hi
    I think that in both of your programs you have used variable "k" which is been not initialized to zero or any number. And one more thing that i doubt is that your strcat() method will work on int data type or not. Make these two changes in your program and see if the program is working fine. If it does not then do post back.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Array correction

    Hi
    I have read both of your code and I am suggesting some to the changes to you. Many be then this will work.
    In your union program
    you have to initialize k = 0
    Then there is no need for this part
    Code:
    else
    c[k]!=x[i];
    The following part of the code will not work as b is not a string. b is array of integers.
    Code:
    strcat(b,c);
    printf("%s",b);
    In your intersection program
    you have to initialize k = 0
    Then there is no need for this part
    Code:
    else
    c[k]!=x[i];
    This part of the code will not print intersection because the intersection values are saved in array c. so you have to print the array c.
    Code:
    printf("%s",b)

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Array correction

    Hi
    Thanks for both of you. i am highly grateful for your efforts. I have tried to follows the step which were posted by you to correct the code, but unfortunately the my code is still not working. I am using windows vista and I think there is a problem which running a c program because it show nothing in the dos screen other some silly symbols. Please I need your help guys.

Similar Threads

  1. HTC Titan- Auto correction.
    By !Shea! in forum Portable Devices
    Replies: 1
    Last Post: 20-11-2011, 06:16 AM
  2. Automatic time correction via NTP servers in Firewall
    By Bruno007 in forum Networking & Security
    Replies: 5
    Last Post: 07-01-2011, 07:28 PM
  3. Spelling Correction is not working properly on the iPad
    By Rupashri in forum Portable Devices
    Replies: 4
    Last Post: 23-12-2010, 04:30 PM
  4. Image correction problem in Photo
    By Eber in forum Windows Software
    Replies: 5
    Last Post: 19-01-2010, 02:00 AM
  5. Correction of a code in vb.net
    By Gefry in forum Software Development
    Replies: 3
    Last Post: 28-04-2009, 03:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,719,981.22677 seconds with 16 queries