GeeksforGeeks » Object oriented queries

Using console application to create this program.

(6 posts)
  • Started 6 months ago by REMYA.T.S.
  • Latest reply from Sharad Dixit

Tags:

  1. REMYA.T.S.
    guest
    Posted 6 months ago #

    Can you specify a porgram to print the numbers from 1 to 10 and their squares without using a loop?

  2. kartik
    Moderator
    Posted 6 months ago #

    #include <stdio.h>
    
    /* Prints numbers from 1 to n */
    void printNos(unsigned int n)
    {
      if(n > 0)
      {
        printNos(n-1);
        printf("%d --> %d\n",  n, n*n);
      }
      return;
    }
    
    /* Driver program to test printNos */
    int main()
    {
      printNos(10);
      getchar();
      return 0;
    }
    
  3. pranay
    guest
    Posted 5 months ago #

    void main()
    {
        static int i=0;
        switch(i)
        {
        case 10:
            exit(0);
        default:
            printf("\n%d >>> >>> >>> %d",i++,I*i);
        }
        main();
    }
    
  4. prat
    guest
    Posted 5 months ago #

    nice logic pranay, but 10 is also included.

  5. pranay
    guest
    Posted 5 months ago #

    oops! my bad,
    just change the case 10 to case 11 :)

  6. Sharad Dixit
    guest
    Posted 5 months ago #

    #include <stdio.h>
    int disp(int i)
    {
            printf(" i = %d  square %d\n", i, i*i);
            return (i ^ 10) && disp(-(~i));
    }
    
    int main(void)
    {
            disp(1);
    }
    

Reply

You must log in to post.

RSS feed for this topic