Showing posts with label puzzle. Show all posts
Showing posts with label puzzle. Show all posts

Code: Towers of hanoi - write a program to solve Towers of Hanoi -

#include<stdio.h>
int TOWER(int n, char beg, char aux, char end);

int TOWER(int n, char beg, char aux, char end)
         {
           if (n==1)
               printf("\nmove disk %d from %c to %c", n, beg, end);
           else
                {
                    TOWER(n-1,beg,end,aux);
                    printf("\nmove disk %d from %c to %c", n, beg, end);
                    TOWER(n-1,aux, beg, end);
                    return 0;
                }
         }
int main()
        {
            int n;
            printf("TOWER OF HANOI:\n");
            printf("\nHow many disk: ");
            scanf("%d", &n);
            if(n<1)
                {
                    printf("INVALID DISK MOVEMENT");
                    return 0;
                }
             TOWER(n,'A', 'B', 'C');
             return 0;
        }

Write a C program to display a triangle of digits as follows. Number of rows is entered by keyboard....



          1

               2  2

             3  3  3

           4  4  4  4

         5  5  5  5  5

             6  6  6  6  6  6


#include<stdio.h>
 int main()
   {
     int  i, j, sp, n;
     printf( "How many line: " );

Write a C program to display a triangle of digits as follows. Number of rows is entered by keyboard

 
  1
        2 2
        3 3 3
        4 4 4 4
        5 5 5 5 5
        6 6 6 6 6 6


#include<stdio.h>
int main()
  {
     int   i,  j,  n;
     printf("Enter the number of line: ");