Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1

    Default unsaon pag remove sa duplicates sa array using c language


    mga bro..!!!tabang palihog! low level pako na IT student.. naa me exercise..maghimo ug program na mu accept ug N amount of integers.. range sa pde ma input is 10-50 only..and dli xa mudawat ug duplicate nga integer.. so far..akong nakuha pa is kadto tanan..except sa duplicate2x part...


    patabang ko plzz mga programming mazterss1!


    mao pa ni code na ako na himo...

    #include<stdio.h>
    #include<conio.h>
    #define N 10
    #define M 10

    main()

    {
    int num[N],num2[M],i;
    clrscr();
    printf("Please Input numbers only from 10-50:\n");
    for(i=0;i<N;i++)
    {
    scanf("%d",&num[i]);
    if (num[i]>=10&&num[i]<=50)
    {}

    else
    {
    for(;
    {
    printf("Invalid. Please enter only values within the range 10-50. Enter again.\n");
    scanf("%d",&num[i]);
    if (num[i]>=10&&num[i]<=50)
    break;
    }

    }
    }
    clrscr();
    for (i=0;i<10;i++)
    {
    printf("%d\n",num[i]);
    }


    getch();

    }

  2. #2
    bai, akong suggestion ani bai
    imong i sort ang mga numbers sa imong array everytime muinsert ka arun mas dali mucheck ug duplicates
    for example
    sud sa imong array is "2","6","12","30"
    assume nko na imo ng na sort kada input and mucheck sad ka everytime
    anyways if mu-input ang user ug "15"
    icheck nimo ang last number sa imong array so which is "30" so dako pa man cya sa 15 so index-1 ta so we can get "12" again we check sa karun less than 15 man cya so psabot wala juy 15. then insert 15 sa imong array so imong array is "2","6","12","30","15" then sort nimo much better buhat kag function na tig sort user quicksort or any sorting algo. arun mahimong "2","6","12","15","30"

    this isn't the best solution. mao rani akong nahunahunaan na dali solution myta mktabang sad ni ug gamay

  3. #3
    #include <string.h>

    ....
    int check; //use it globally or locally
    int flag = 0;
    void main
    {

    ....

    scanf("%d",&num[i]);

    for(check=0;check<=strlen(num);check++)
    {
    if(num[i]==num[check])
    {
    break the loop,
    flag = 1;
    do something ...
    }
    else
    {
    continue parsing..
    }
    }

    if(flag==1)
    {
    flag = 0;
    error message: already in array
    }
    else
    {
    add to array
    }
    continue with the code;
    }

    sorry, medyo bad ko sa C language. more on java ko.
    but I hope you get the idea..

    traverse the Array.
    then, imu i-check tagsa2x ang imung na-input nga value to the traversed array.
    then, if nakit.an, flag =1, then break the loop.
    if wala nakit.an, flag will always = 0;

  4. #4
    the code I gave above is bad for "BILLIONS" of data.
    it can serve thousands of data.
    frustrating on millions of data.

    but since, gamay ra man pud imung data..
    ok ra na..

    sakto pud ang kang slackboy. sorting sa data ang maayo.

    anyways, don't forget the strlen or "String Length"
    and the #include<string.h>

  5. #5
    ^^ memory intensive kaayu kung imo itraverse permi hehehe
    pero kung gamay ra imong kuhaun na data oki ra imo itraverse

  6. #6
    kalimot nako sa c but i'll can make sort of pseudo for this


    variables:
    data[] = array to store data
    temp = to store scanned data

    create a loop that continues when data is not full (if you can use a built-in func OR just counter if none),
    - what loop is good for this?, definitly not for loop
    - use a function in C to count non-empty values in array, unsa na?
    - if wlay automatic, alternative is using a counter, count++ inside the block where you store no-duplicate-data in array.

    inside loop:
    first, get input from user store it in temp

    if first input, store it directly to array (counter++),
    then proceed to scan again

    else compare temp with each data content by looping (pwde ba recursive?)
    - para efficient use count variable as criteria in the for loop (if no func to give count of non-empty cells in array data)

    (you'll probably use a flag here)
    if temp has the same data already stored,
    - you'll prompt that input data already inputted
    - proceed to scanning again

    else store temp and (counter++) then proceed to scanning again

    if data is full or if counter is satisfied, the loop (outer) for scanning ends.



    i hope this works. hihihi

    -
    ngano mawla ang indentation inig display sa post? but inig edit kay ma indent ra.
    Last edited by aozora; 06-24-2010 at 01:34 PM.

  7. #7
    - i agree with the sorted array. use a sorting algorithm if you must sort the inputted data in the array.. hmmm. quick sort is good. although, i dont believe that you have to sort the array everytime the user inputs something. you just have to find the proper place for the newly inputted data within the array, and insert it there.
    - everytime the user inputs a number, seach for the inputted number in the array... i dont agree with the 'index - 1' way that was mentioned earlier. use an algorithm for the search.. hmmm.. i suggest binary search.
    - use functions for the sorting and the searching.. or even getting the data from the user.

    so your pseudocode would be..

    ask for user input
    search for the input in the sorted array
    if not found, add it in its proper place within the array, otherwise display a message

    hope this helps

  8. #8
    also.. iwrap imong codes in [code] tags kay para dili maguba inig post nimo

  9. #9
    actually di na mo kinanlan mag.sortsort pa...

    heres the pseudocode...i'm not good in c because I am a java programmer but below should do the trick
    Code:
    int N;                //the number of numbers to be inputed
    int numOut[41]; //there are only 41 number from 10-50
    int i;                //iterations
    
    //Ask the user how many numbers he wants to enter
    printf("Please input the number of numbers you want to enter: ");
    
    //get the number
    scanf("%d", &N);
    
    //initialze the array that will hold the numbers
    int numIn[N];
    
    //inform the user to input the numbers
    printf("Pls. enter numbers from 10 to 50");
    
    //get the numbers
    for(i=0; i<N; i++)
    {
         scanf("%d", numIn[i]);
    }
    
    
    //initialize the array that will hold the number to be displayed
    for(i=0; i<41; i++)
    {
        numOut[i] = 0;
    }
    
    //traverse  numIn[] to look for valid inputs
    //if input is valid, mark the array index by 1
    for(i=0; i<N; i++)
    {
          if(numIn[i]>=10 && numIn[i]<=50)
         {
             numOut[numIn[i]-10] = 1;
         }
    }
    
    //dispaly the numbers
    
    for(i=0; i<41; i++)
    {
         if(numOut[i]==1)
         {
            printf("%d\n", &i+10);
         }
    }

  10. #10
    Quote Originally Posted by crickwalter View Post
    actually di na mo kinanlan mag.sortsort pa...

    heres the pseudocode...i'm not good in c because I am a java programmer but below should do the trick
    Code:
    int N;                //the number of numbers to be inputed
    int numOut[41]; //there are only 41 number from 10-50
    int i;                //iterations
    
    //Ask the user how many numbers he wants to enter
    printf("Please input the number of numbers you want to enter: ");
    
    //get the number
    scanf("%d", &N);
    
    //initialze the array that will hold the numbers
    int numIn[N];
    
    //get the numbers
    for(i=0; i<N; i++)
    {
         scanf("%d", numIn[i]);
    }
    
    
    //initialize the array to dispay the numbers
    for(i=0; i<41; i++)
    {
        numOut[i] = 0;
    }
    
    //traverse the numbers inputed to look for valid inputs
    //if input is valid, mark the array index by 1
    for(i=0; i<N; i++)
    {
          if(numIn[i]>=10 && numIn[i]<=50)
         {
             numOut[numIn[i]] = 1;
         }
    }
    
    //dispaly the numbers
    
    for(i=0; i<41; i++)
    {
         if(numOut[i]==1)
         {
            printf(i+10);
         }
    }

    you are right nga dili na kinahanglan magsortsort pa to get the job done. actually its an efficiency trade-off between sorting and not sorting the array.

    also.. with your code or pseudocode, basig nasayop lang ko, pero wala ko kita ug part diha nga gitangtang ang mga duplicates or that your code did something about the duplicates. all it did, i think, is mark and display the valid inputs (kadtong between 10 and 50), but not a thing on duplicates, which is ang main topic diri.

    about sa sorted array, i suggested it because i think it would be more efficient, if the array was sorted, to find the duplicates

  11.    Advertisement

Page 1 of 3 123 LastLast

Similar Threads

 
  1. unsaon pag upload ug pics sa istorya.net photo gallery?
    By mad_scientist77 in forum Support Center
    Replies: 3
    Last Post: 01-08-2012, 05:56 PM
  2. unsaon pag remove sa side bars
    By ellakylamarie in forum Websites & Multimedia
    Replies: 0
    Last Post: 10-13-2010, 06:18 AM
  3. Unsaon pag remove sa COMBOFIX ?
    By Darkm8 in forum Software & Games (Old)
    Replies: 7
    Last Post: 07-21-2009, 01:35 PM
  4. Replies: 4
    Last Post: 02-25-2008, 08:32 AM
  5. Replies: 0
    Last Post: 03-06-2006, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top