Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Insert the information of two books

C# Sharp STRUCTURE: Exercise-9 with Solution

Write a program in C# Sharp to insert the information of two books.

Sample Solution:-

C# Sharp Code:

using System;

struct book 
{
	public string title;
	public string author;
}
public class strucExer9
{
public static void Main ()  
	{
	int nobook = 1000;  
	book [] books =new book [nobook];  
	int i,j,n=1,k=1;  
	Console.Write("\n\nInsert the information of two books :\n");
	Console.Write("-----------------------------------------\n");    
			for(j=0;j<=n;j++)
				{
			    Console.WriteLine("Information of book {0} :",k);

			    Console.Write("Input name of the book : ");
			    books[j].title= Console.ReadLine();
 
			    Console.Write("Input the author : ");
			    books[j].author= Console.ReadLine();
                k++;
			    Console.WriteLine();
			    }

	        for(i = 0;i <=n;i++)
	        {
            Console.WriteLine("{0}: Title = {1},  Author = {2}", i+1, books[i].title, books[i].author);
            Console.WriteLine();
	        }

	}
}

Sample Output:

Insert the information of two books :                    
-----------------------------------------                
Information of book 1 :                                  

Input name of the book : BASIC                           

Input the author : S.TROELSTRA                           
                                                         
Information of book 2 :  
                                
Input name of the book : C+ 
                             
Input the author : G.RTRTG                               

1: Title = BASIC,  Author = S.TROELSTRA                  
                                                         
2: Title = C+,  Author = G.RTRTG 

Flowchart:

Flowchart: Insert the information of two books.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to demonstrates struct initialization without using the new operator.
Next: Write a program in C# Sharp to implement a method that returns a structure including calling the method and using its value.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.