Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22
  1. #11

    Quote Originally Posted by crickwalter View Post
    //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;
    }
    }


    [/code]
    kani nga code bai mao na ni mag.eliminate sa duplicate. ex. if nag input kag 15, so numOut[5] ==1. So pag display ani sa for loop, pag.abot niya ug i==5, i.display niya kay 15. basaha ra ang code bai...

  2. #12
    Take note lang bai nga dili ang sulod sa array ang gi.display kundili ang index plus 10 which is

    i+10

    naa na sa last part kon giunsa pag.display

  3. #13
    ahh uu.. na.gets na nako bay. murag sakto ni imong algo. ok ra ni siya kung gamay ra ang valid numbers.. like sa gi.specify ra ts.

    pero dili ni scalable. which means if muingon ang maistra nga usbon niya ang valid numbers to 1 - 1000000. syagit ni.

    but for valid numbers nga up to 32767 lang, ok ra ni. mu.work ra ni. although declaring an array of size 32767 just to display, say, 10 valid inputs is probably stupid.. but mu work ra ni.

  4. #14
    @crickwalter
    bai ang iyang gpangayu is dili daw mudwat ug duplicate numbers so ang maayu buhaton mgchecking after sa input

    katong imong code sa akong pagsabot imo gdwat tanang input sa user nya imo gpang remove ang duplicate. so if every input cyag 10 ka "5" ang idisplay nya usa ka 5 nlng?

  5. #15
    mga bro!!salmat au sa inyong tabang!!! pero sad to say..la ayu ko ka gets..

    low level pa jud ko..as in..level 1 pa..if ever naa level 0 naa ko dha na level..haha..!

    pde ko mangayo lang ug part sa code na i chek sa program every input?

    wla pd ko kabalo unsaon pag sort..haha..la me gitudluan ana..ako functions na nhblan are: printf,scanf,define,clrscr,getch,if,loops,...


    agen!ty au sa pag reply!! pa help pa jud ko palihog..

  6. #16
    Quote Originally Posted by zengatsu View Post
    ahh uu.. na.gets na nako bay. murag sakto ni imong algo. ok ra ni siya kung gamay ra ang valid numbers.. like sa gi.specify ra ts.

    pero dili ni scalable. which means if muingon ang maistra nga usbon niya ang valid numbers to 1 - 1000000. syagit ni.

    but for valid numbers nga up to 32767 lang, ok ra ni. mu.work ra ni. although declaring an array of size 32767 just to display, say, 10 valid inputs is probably stupid.. but mu work ra ni.

    Yup, di na xa flexible. If i.change ang policy sa mga numbers nga i.input dapat i.change sad gyod ang code. di sad ni extendible kay array. Beginner pman ang TS mao ing.ani ni xa. Mas maayo kon vector ang gamiton.

    Well ma.solve naman ang problem ani.

  7. #17
    Quote Originally Posted by slackboy View Post
    @crickwalter
    bai ang iyang gpangayu is dili daw mudwat ug duplicate numbers so ang maayu buhaton mgchecking after sa input

    katong imong code sa akong pagsabot imo gdwat tanang input sa user nya imo gpang remove ang duplicate. so if every input cyag 10 ka "5" ang idisplay nya usa ka 5 nlng?

    Ok, pwede man di niya i.accept ang number kon dili from 10 to 50 pag.input pa lang sa user ug di xa modawat ug duplicate....depende na na sa TS kon unsaon niya pag.modify ang code...

    pero pwede ing.ani...this is very far effecient compared to having the numbers sorted.

    Code:
    int N;                //the number of numbers to be inputed
    int numbers[41]; //there are only 41 number from 10-50
    int i;                //iterations
     
    //initialize the array that will hold the numbers
    for(i=0; i<41; i++)
    {
        numbers[i] = 0;
    }
     
    //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);
     
    //inform the user to input the numbers
    printf("Pls. enter numbers from 10 to 50");
     
    //get the numbers
    for(i=0; i<N; i++)
    {
         int num=0;
         scanf("%d", &num);
     
         //if the number is valid flag the index corresponding to the number entered
         if(num>=10 && num<=50 && numbers[num-10]!=1)
         {
               numbers[num-10] = 1;
          }
          //if the number is invalid, output a message and repeat the asking of a number
          else
          {            
                printf("Invalid or duplicate Number. Pls input another number.\n");
                i--;
           }        
    }
     
    //dispaly the numbers
    for(i=0; i<41; i++)
    {
         if(numbers[i]==1)
         {
            printf("%d\n", &i+10);
         }
    }

  8. #18
    Quote Originally Posted by DreaderX View Post
    mga bro!!salmat au sa inyong tabang!!! pero sad to say..la ayu ko ka gets..

    low level pa jud ko..as in..level 1 pa..if ever naa level 0 naa ko dha na level..haha..!

    pde ko mangayo lang ug part sa code na i chek sa program every input?

    wla pd ko kabalo unsaon pag sort..haha..la me gitudluan ana..ako functions na nhblan are: printf,scanf,define,clrscr,getch,if,loops,...


    agen!ty au sa pag reply!! pa help pa jud ko palihog..
    Ok ra na bai, basaha lang ang comments sa ako code gihatag. mao na na oi imong pseudocode. Spoon feed na gani na bai. balik balika lang ug basa para masabtan. i.try lang na ug program. sige lang ug try hangtod makuha nimo.

  9. #19
    @DreaderX: use crickwalter's solution. it works, and it's actually relatively efficient given that the requirements are as what you described above - only numbers 10 -50 are accepted

    @crickwalter: i say that your code is 'relatively' efficient because when it comes to memory allocation, it is not efficient. if the user would choose to input only 2 numbers, why would you have to allocate 51 int spaces? how much more if the constraint on the valid numbers is lifted? although, in fairness to you, your code actually works, and it will work fast for the premise that the ts gave. and, in that light, i am thinking that it is up to the ts to look for and implement the areas for improvements. he is a student after all. hehehe. oh, and yes, you are spoon feeding him.. haha
    Last edited by zengatsu; 06-28-2010 at 09:53 AM.

  10. #20
    if i understand the TS properly, one of the requirement is that the program must be able accept N number of unique integers. that means if it is set to accept 3 (unique) integers, a user can attempt to enter 6 integers but if 4 of which is just a duplicate of 2 already inputted then the program will just continue to ask for another unique number.

    below is a modification of @crickwalter's code to satisfy above requirement. btw, the code below has a side effect of printing the inputted numbers in ascending order & not by the sequence they were entered by the user.

    Code:
    #include<stdio.h>
    
    main()
    {
       int N=0;                //the number of numbers to be inputed
       int nums[51]; //51 so we could do away with -1 during assignment ;-)
       int i;                //iterations
       int tmp; //temp holder for the number inputted by the user
    
       do {
          //Ask the user how many numbers he wants to enter
          printf("Please input the number of numbers you want to enter (max is 41): ");
          scanf("%d", &N);
       } while (N<=0 || N>41);
    
       //initialize the array that will hold the number to be displayed
       for(i=0; i<51; i++)
          nums[i] = 0;
    
       i=0; //reset for reuse
       do {
          //inform the user to input the numbers
          printf("Pls. enter a number between 10 to 50: ");
          scanf("%d", &tmp);
    
          if (tmp >= 10 && tmp <= 50)
             if (nums[tmp])
                printf("Number already entered\n");
             else
                nums[tmp] = ++i; //this value could be use to sort accdg to the sequence the numbers were entered.
          else
             printf("Number must be between 10 to 50\n");
       } while (i<=N);
    
       //dispaly the numbers
       for(i=0; i<51; i++)
          if(nums[i])
             printf("%d\n", i);
    }
    @TS
    ayaw lang sa kabalaka anang optimization gi mention sa mga guys. specially student pa ka. the thing to remember is, make your code run according to spec/reqs then optimize. not before
    Last edited by devnull; 06-26-2010 at 12:38 AM. Reason: code cleanup

  11.    Advertisement

Page 2 of 3 FirstFirst 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