need help to write a program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sia khan
    New Member
    • Oct 2006
    • 6

    need help to write a program

    please help me how could i get the output ?
    1
    12
    123
    1234
    123
    12
    1
    if i m using C++ array and next qusestion is how can i search an integer from two dimensional array?
  • Karan
    New Member
    • Sep 2006
    • 5

    #2
    Originally posted by sia khan
    please help me how could i get the output ?
    1
    12
    123
    1234
    123
    12
    1
    if i m using C++ array and next qusestion is how can i search an integer from two dimensional array?
    Hi,
    You have to use two for loops to display these kind of output.

    the for loops can be:-

    for( i=1; i<5; i++)
    for( j=1; j<=i; j++)
    print ( j )


    and to search a integer in an 2D array u hve to use again two for loops.

    Comment

    • sircool
      New Member
      • Oct 2006
      • 12

      #3
      Originally posted by sia khan
      please help me how could i get the output ?
      1
      12
      123
      1234
      123
      12
      1
      if i m using C++ array and next qusestion is how can i search an integer from two dimensional array?
      karan is true i would help you about finding a integer from the 2D arrays
      you shold write 2 for loops and a if state like that

      int search;

      for(int i;i<size;i++)
      for(int j;j<size;j++)
      if(array[i][j]==search)
      return 0;

      can be...

      Comment

      • sia khan
        New Member
        • Oct 2006
        • 6

        #4
        Originally posted by sircool
        karan is true i would help you about finding a integer from the 2D arrays
        you shold write 2 for loops and a if state like that

        int search;

        for(int i;i<size;i++)
        for(int j;j<size;j++)
        if(array[i][j]==search)
        return 0;

        can be...
        thanks for helping but one thing that i've forget to mention that i m following this method but it's not doing....and always give output not found this program is behaving miserably
        can u tell me this from the first thing to the end i mean from #include<iostre am.h>.........t o ..........getch ();}
        i'll very thankful to u please reply me as soon as possible thanks alot again

        Comment

        • sia khan
          New Member
          • Oct 2006
          • 6

          #5
          Originally posted by Karan
          Hi,
          You have to use two for loops to display these kind of output.

          the for loops can be:-

          for( i=1; i<5; i++)
          for( j=1; j<=i; j++)
          print ( j )


          and to search a integer in an 2D array u hve to use again two for loops.
          hello Karan...thanks to help but Karan i m still learning and really,still i dont understand how to initiate this program please could u write this program again clearly besides giving me hints ....i 'll be very thankful to u
          waiting for ur reply

          Comment

          • muzammil azmi
            New Member
            • Oct 2006
            • 3

            #6
            code of the your problem is very simple


            #include <iostream.h>
            #include <conio.h>
            void main()
            {
            clrscr();
            int search;
            int arr[row][colom]={{here enter the element of array}};
            cout<<"enter the element to be search";
            cin>>search;
            for(int i=0;i<=row;i++)
            {
            for(int j=0;j<=colom;j+ +)
            {
            if(arr[i][j]==search)
            break;
            }
            }
            cout<<"no can be found at the position of:" <<arr[i][j];
            getch();
            }

            Comment

            • sia khan
              New Member
              • Oct 2006
              • 6

              #7
              Originally posted by muzammil azmi
              code of the your problem is very simple
              oh thank u so much u've made my day
              its working inshallah if i got type of problem i'll ask u in future ok thanks once again

              Comment

              • sia khan
                New Member
                • Oct 2006
                • 6

                #8
                i need again help in writing a program
                how can i make a program which can calculate factorial using C++

                Comment

                • D_C
                  Contributor
                  • Jun 2006
                  • 293

                  #9
                  Code:
                  int factorial(int n)
                  {
                    int result = 1;
                    while(n > 1)
                    {
                      result *= n;
                      n--;
                    }
                    return result;
                  }

                  Comment

                  • rawinder dhillon
                    New Member
                    • Oct 2006
                    • 8

                    #10
                    hi khan,
                    this is in simple c++
                    if you want to use class or some other concepts than will send you



                    void fac(int num)
                    {
                    int fac=1;
                    for(i=num;i>=1; i--)
                    {
                    fac=fac*i;
                    }
                    cout<<"Factoria l ="<<fac;
                    getch();
                    }
                    Rawinder dhillon

                    Comment

                    • aghadiri
                      New Member
                      • Oct 2006
                      • 1

                      #11
                      try this

                      A recursive factorial

                      int fact(int n)
                      {
                      if (n == 0)
                      return 1;

                      return ( n * fact( n-1 ) );
                      }

                      Comment

                      Working...