User Profile

Collapse

Profile Sidebar

Collapse
Nhd
Nhd
Last Activity: Jan 22 '07, 12:55 PM
Joined: Aug 31 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Nhd
    replied to Can someone look through this code for me?
    in C
    No, ur not... Its juz that the question itself is very confusing... I'll explain it..

    when an input is an even number, the outcome will be number=number/2. thats where you can see the number above from 16, is divided into two until we get 1. when it reaches 1, it is considered end of the cycle.

    however, when an input is an odd number, the outcome is number=3*number +1, and hence in this case, since 5 is an odd number,...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to Can someone look through this code for me?
    in C
    Hi... I can only explain this much to u cos i only know what is cycle length but not maximum cycle length...


    Total numbers of elements in sequence until it reaches 1, including input number and 1, is called cycle of the sequence of that given input no. For example if user input 5 then the sequence will be something like this.

    5 16 8 4 2 1 = cycle length equals to 6.....
    See more | Go to post

    Leave a comment:


  • Nhd
    started a topic Can someone look through this code for me?
    in C

    Can someone look through this code for me?

    Code:
    #include <iostream>
    #include <sstream>
    #include <string>
    
    using namespace std;
    int main(int argc, char* argv[]) {
        
        int Count1 = 1;
        int Count2 = 1;
        int Count = 0;
        int number1,number2;
    
    cin>>number1>>number2;   
        
        while (number1 != 1)  
        {      
               if (number1%2==0)
    ...
    See more | Go to post

  • Nhd
    replied to How do we write odd function in an if-else statement
    in C
    Thanks shardul316 and horace1..

    Ive goten that part right already...

    However, may i noe how do we continuously continue this statement. i tried using a for loop, but it doesnt work..

    after i input in 22, 11 will be the output that i'll get.. but im expected to get this output instead -> 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1..

    which means that the output is continuously fed into...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to How do we write odd function in an if-else statement
    in C
    is the the % operator? meaning i shud juz write it as

    if (n%2)
    {
    n=3*n+1;
    }

    ok, thk u so much, i get this already... i can go to the second part now... Thanks alot...
    See more | Go to post

    Leave a comment:


  • Nhd
    started a topic How do we write odd function in an if-else statement
    in C

    How do we write odd function in an if-else statement

    I'm facing some problems.. Its very basic but i cant seems to remember how to go abt doing it...

    Im supposed to input in a value
    if it is 1, then im supposed to stop the program,
    if n is odd, then n=n*3+1,
    else n=n/2

    What ive written is

    int n;

    cin>>n;

    if (n==1)
    {
    cout<<n<<endl;...
    See more | Go to post

  • Nhd
    replied to conversion from infix to postfix
    in C
    hi Banfa.. my purpose in typing out those codes is to convert infix to postfix..

    for example:
    Sample input 1
    1 + 2 * 3 - 4 / 2 + 5 * 6
    Sample output 1
    35

    Sample input 2
    ( 10 + 20 ) * 30 - 4000 / 20 + 50 * 60
    Sample output 2
    3700

    I'm trying to write a program for this... and my notes shows only these codes, the one that i type out...

    what...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to conversion from infix to postfix
    in C
    Thanks Banfa for ur help.... but do u mind helping me to check my program please.... I've been struggling from juz now and i still cant do it....

    Code:
    #include <iostream>
    #include <stack>
    #include <vector>
    #include <sstream>
    using namespace std;
    
    int eval_postfix(const vector<char>&v, stack<int>&st);
    int main()
    {
          string
    ...
    See more | Go to post
    Last edited by Banfa; Sep 20 '06, 05:10 PM. Reason: Added [code]...[/code] round the code

    Leave a comment:


  • Nhd
    replied to conversion from infix to postfix
    in C
    for this function, for the 2nd sentence , may i noe how do i declare "begin"? i hav error regarding this.... should i declare it in main function or in its own function itself...

    int eval_postfix(co nst vector<char>&v, stack<int>&st)
    {
    for (vector<char>:: const_iterator ptr = v.begin(begin() ; ptr !=v.end(); ++ptr)
    {
    if ('0'<= *ptr...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to conversion from infix to postfix
    in C
    Hi... I put the "int eval_postfix(co nst vector<char>&v, stack<int>&st)" out of the main, i still get error.. the error i get is something to do with this "int main()".. but i cant remove the "int main()"..... I'm sory to bother u but im really weak in my programming...

    #include <iostream>
    #include <stack>
    #include <vector>
    #include <sstream>...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to conversion from infix to postfix
    in C
    Hi i modify my codes but i'm unable to execute it.... can anyone help me to spot the mistake.. thanks

    Code:
    #include <iostream>
    #include <stack>
    #include <vector>
    #include <sstream>
    using namespace std;
    
    int main()
    {
          string line, str;  
          int number;
          
          cout<<"Sample Input:"<<" "<<endl;
    ...
    See more | Go to post
    Last edited by Banfa; Sep 20 '06, 09:03 AM. Reason: Added [code]...[/code] round the code

    Leave a comment:


  • Nhd
    replied to conversion from infix to postfix
    in C
    Hi can anyone help me to check this... Im lost in my own program... I noe some part of it is wrong... can anyone tell me... thanks

    #include <iostream>
    #include <stack>
    #include <vector>
    #include <sstream>
    using namespace std;

    int main()
    {
    string line, str;
    int number;

    cout<<"Sample Input 1"<<"...
    See more | Go to post

    Leave a comment:


  • Nhd
    started a topic conversion from infix to postfix
    in C

    conversion from infix to postfix

    Hi... I need a program to convert an infix arithmetic expression to postfix with the use of stacks... Can anyone tell me how do i go about implementing this? thanks
    See more | Go to post

  • Nhd
    replied to How to get individual informations from a file?
    in C
    Hi can i add on a question...

    What if the question requires us to read in from cin all lines of the report and write to cout the required statictic instead of reading from a file...

    How do we modify the above codes so that instead of reading from a file, it reads in from cin...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to A question on designing using ADT
    in C
    hi D_C...

    I tried that before but it still doesnt count the number of lines...
    when i type in File1-0(71%) File2-0(63%) 177, it reads as 2... i have no idea why... shouldn't it read as 1 as i input only 1 sentence... please help me to rectify this problem... thanks so much
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to Finding Max and Min using cin
    in C
    Hi.. i tried but the error is still there.... But i think im on the wrong track after thinking back...

    My input sample is like this:

    File 1 File 2 Lines Matched
    File1-0(71%) File2-0(63%) 177
    File1-1(59%) File2-1(63%) 167
    File1-2(49%) File2-2(54%) 101
    File1-3(42%) File2-3(51%) 130
    File1-4(53%) File2-4(47%) 92
    File1-5(58%) File2-5(57%)...
    See more | Go to post

    Leave a comment:


  • Nhd
    replied to A question on designing using ADT
    in C
    Code:
     #include <iostream> 
    #include <string>
    #include <sstream>
    #include "Moss.h"
    using namespace std;
     
    int main() {
     
    int i=0;
    string oneline, sentence; 
     
    cout<<"File1" << " " << "File2" << " " << "Lines Matched" << endl; 
    cin>>sentence;
    i++;
    ...
    See more | Go to post
    Last edited by Niheel; Sep 5 '06, 12:40 AM.

    Leave a comment:


  • Nhd
    replied to Finding Max and Min using cin
    in C
    Hi, this program is not really working... when i run it, there's an error which states "cin", "cout" and "endl" are undeclared (first use this function).. But why should i declare cin, cout and endl? There's supposed to be no need for any declaration for these rite...?

    #include<iostre am>

    void min_max (int one, int two, int three, int& min, int& max);

    main()...
    See more | Go to post

    Leave a comment:


  • Nhd
    started a topic Finding Max and Min using cin
    in C

    Finding Max and Min using cin

    Write a program that reads daily temperatures, as floats. Read in a loop until an EOF. After the input has been read, print the maximum and minimum values. You can assume that there is at least one input data value.
    Sample input values

    10.0 11.3 4.5 -2.0 3.6 -3.3 0.0


    The output should look something like the following. Formatting may vary.

    Maximum = 11.3
    Minimum...
    See more | Go to post

  • Nhd
    replied to A question on designing using ADT
    in C
    Hi thanks for the info... But i'm still facing problems as in i cant really understand how do i go abt doing this... this is a very tough assignment and i cant handle this... :(...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...