Write program with C# . 1, write a C#program that Show the output according user
ID: 3571108 • Letter: W
Question
Write program with C#
.
1, write a C#program that Show the output according user inputted number.
Example: If user input 5-
5
54
543
5432
54321
5432
543
54
5
.
3, Create a program for library is able to enter name of book name, author and borrower name. However borrower can borrow 5 books maximum at a time and duplicated book information is not allowed to enter. Then show the output of the list of the borrowed book information. Hint: Ask user how many books to enter in program. If user input 5, program is able to input different five book information such as Name of Book, Author Name and Borrower Name.
Explanation / Answer
using System;
class Book{
public string name;
public string author;
public string borrower;
}
public class Test{
public static void Main(){
// Solution 1
Console.Write("Enter a number : ");
int a = Int32.Parse(Console.ReadLine());
string[] S = new string[a];
int k = 0;
while (k < a){
int i = 0;
string s = "";
while (i <= k){
s += (a-i).ToString();
Console.Write(a-i);
i += 1;
}
S[k] = s;
Console.Write(' ');
k += 1;
}
for (int i = a-2; i >= 0; i--){
Console.Write(S[i]+' ');
}
// solution 3
Console.Write("Enter the number of book to borrow : ");
int n = Int32.Parse(Console.ReadLine());
Console.Write("Enter Your Name : ");
string name = Console.ReadLine();
Book[] B = new Book[n];
int j =0;
while (j < n){
Console.Write("Enter Book Name : ");
string book_name = Console.ReadLine();
string auth = Console.ReadLine();
Book b = new Book();
b.name = book_name;
b.author = auth;
b.borrower = name;
B[j] = b;
j++;
}
Console.Write("Book Name " +" " + "Book Author " + " " + "Book Borrower"+" ");
for (int i = 0; i < n; i++){
Console.Write(B[i].name+" "+B[i].author+" "+B[i].borrower+' ');
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.