Saturday, 30 December 2017

C program to read a string with space (Text with space)

#include <stdio.h>

int main (int argc, char const *argv[])
{
    char name[20];
    printf("enter your name \n");
    scanf("%[^\n]s",name);
    printf("%s\n", name);
    return 0;
}



Thursday, 28 December 2017

TOWER OF HANOI


#include<stdio.h>
#include<conio.h>
void towers(int, char, char, char);
int main()
{
    int num;
    clrscr();
    printf("Enter the number of disks : ");
    scanf("%d", &num);
    printf("The sequence of moves involved in the Tower of Hanoi are :\n");
    towers(num, 'A', 'C', 'B');
  getch();

}

void towers(int num, char frompeg, char topeg, char auxpeg)
    {
    if (num == 1)
    {
     printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
      return;
    }

    towers(num - 1, frompeg, auxpeg, topeg);
    printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
    towers(num - 1, auxpeg, topeg, frompeg);
}