Tuesday, December 23, 2014

Simplified C Programs



17. Program
#include 
#include 
#include 
typedef struct Books
{
   char  title[50];
   char  author[50];
   char  subject[100];
   int   book_id;
} Book;
 
int main( )
{
clrscr();   
Book book;
 
   strcpy( book.title, "C Programming");
   strcpy( book.author, "Nuha Ali"); 
   strcpy( book.subject, "C Programming Tutorial");
   book.book_id = 6495407;
 
   printf( "Book title : %s\n", book.title);
   printf( "Book author : %s\n", book.author);
   printf( "Book subject : %s\n", book.subject);
   printf( "Book book_id : %d\n", book.book_id);
 
   return 0;
   getch();
}


Output
Book  title : C Programming
Book  author : Nuha Ali
Book  subject : C Programming Tutorial
Book  book_id : 6495407

18. Program
#include 
#include 
#define TRUE  1
#define FALSE 0
 
int main( )
{
   printf( "Value of True : %d\n", True);
   printf( "Value of False : %d\n", False);
 
   return 0;
   getch();
}

Output
Value of True : 1
Value of False : 0

19. Program
#include 
#include 
int main( )
{
   int c;
 
   printf( "Enter a value :");
   c = getchar( );
 
   printf( "\nYou entered: ");
   putchar( c );
 
   return 0;
   getch();
}

Output
Enter a value : this is test
You entered: t
 
20. Program
#include 
#include 
int main( )
{
   char str[100];
 
   printf( "Enter a value :");
   gets( str );
 
   printf( "\nYou entered: ");
   puts( str );
 
   return 0;
 getch();
}

Output
Enter a value : this is test
You entered: This is test

No comments:

Post a Comment