Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Sum of 3 Numbers
- using System;
- //Write a program that reads 3 real numbers from the console and prints their sum. Examples:
- //a b c sum
- //3 4 11 18
- //-2 0 3 1
- //5.5 4.5 20.1 30.1
- class Program
- {
- static void Main()
- {
- double a = double.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- double c= double.Parse(Console.ReadLine());
- Console.WriteLine(a+b+c);
- }
- }
- //2. Print Company Information
- using System;
- //A company has name, address, phone number, fax number, web site and manager. The manager has first name,
- //last name, age and a phone number. Write a program that reads the information about a company and its manager
- //and prints it back on the console.
- //program user
- //Company name: Software University
- //Company address: 26 V. Kanchev, Sofia
- //Phone number: +359 899 55 55 92
- //Fax number:
- //Web site: http://softuni.bg
- //Manager first name: Svetlin
- //Manager last name: Nakov
- //Manager age: 25
- //Manager phone: +359 2 981 981
- //
- //Software University
- //Address: 26 V. Kanchev, Sofia
- //Tel. +359 899 55 55 92
- //Fax: (no fax)
- //Web site: http://softuni.bg
- //Manager: Svetlin Nakov (age:
- //25, tel. +359 2 981 981)
- class Program
- {
- static void Main()
- {
- string[] infoList = new string[9] { "Company name: ", "Company addreess: ", "Phone number: ", "Fax number: ",
- "Web site: ", "Manager first name: ", "Manager last name: ", "Manager age:",
- "Manager phone: " };
- string[] infoFromUser = new string[9];
- for (int i = 0; i < infoList.Length; i++)
- {
- Console.Write(infoList[i]);
- infoFromUser[i] = Console.ReadLine();
- }
- Console.WriteLine("------------------------------");
- string[] infoPrint = new string[8] { "", "Address: ", "Tel. ", "Fax: (no fax)", "Web site: ", "Manager: ", "age.", "tel. "};
- for (int i = 0; i < infoPrint.Length-2; i++)
- {
- Console.WriteLine();
- Console.Write(infoPrint[i]+infoFromUser[i]);
- }
- Console.Write(" "+infoFromUser[6]+"( "+infoPrint[6]+"\n"+infoFromUser[7]+" "+infoPrint[7]+infoFromUser[8]+")");
- Console.WriteLine();
- }
- }
- // 3. Circle Perimeter and Area
- //Write a program that reads the radius r of a circle and prints its perimeter and area formatted with 2 digits after the
- //decimal point. Examples:
- //r perimeter area
- //2 12.57 12.57
- //3.5 21.99 38.48
- class Program
- {
- static void Main()
- {
- //A = Pi * r^2
- //P = 2 * Pi * r
- Console.WriteLine("Write your radios...");
- double r = double.Parse(Console.ReadLine());
- double perimeter = 2 * Math.PI * r;
- double area = Math.PI * r * r;
- Console.WriteLine("Perimetar = {0}, Area = {1}",perimeter,area);
- }
- }
- // 4. Number Comparer
- using System;
- //Write a program that gets two numbers from the console and prints the greater of them. Try to implement this
- //without if statements. Examples:
- //a b greater
- //5 6 6
- //10 5 10
- //0 0 0
- //-5 -2 -2
- //1.5 1.6 1.6
- class Program
- {
- static void Main()
- {
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- if (a > b)
- {
- Console.WriteLine(a);
- }
- else if (a < b)
- {
- Console.WriteLine(b);
- }
- else if (a == b)
- {
- Console.WriteLine(a);
- }
- }
- }
- //5. Formatting Numbers
- floating-point c and prints
- //them in 4 virtual columns on the console. Each column should have a width of 10 characters. The number a should
- //be printed in hexadecimal, left aligned; then the number a should be printed in binary form, padded with zeroes,
- //then the number b should be printed with 2 digits after the decimal point, right aligned; the number c should be
- //printed with 3 digits after the decimal point, left aligned. Examples:
- //a b c result
- //254 11.6 0.5 |FE |0011111110| 11.60|0.500 |
- //499 -0.5559 10000 |1F3 |0111110011| -0.56|10000 |
- //0 3 -0.1234 |0 |0000000000| 3|-0.123
- class Program
- {
- static void Main()
- {
- int a = int.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- double c = double.Parse(Console.ReadLine());
- string myHexNumber = a.ToString("X");
- string myBinary = Convert.ToString(a, 2);
- Console.WriteLine("|{0,-10}|{1,10:D10}|{2,10:F2}|{3,-10:F3}|",myHexNumber,myBinary,b,c);
- }
- }
- //6. Quadratic Equation
- using System;
- //Write a program that reads the coefficients a, b and c of a quadratic equation ax2 + bx + c = 0 and solves it (prints
- //its real roots). Examples:
- //a b c roots
- //2 5 -3 x1=-3; x2=0.5
- //-1 3 0 x1=3; x2=0
- //-0.5 4 -8 x1=x2=4
- //5 2 8 no real roots
- class Program
- {
- static void Main()
- {
- //double sqrtpart = b * b - 4 * a * c;
- //answer = (b + Math.Sqrt(sqrtpart)) / 2 * a;
- //textBox4.Text = answer.ToString();
- }
- }
- //7. Sum of 5 Numbers
- using System;
- //Write a program that enters 5 numbers (given in a single line, separated by a space), calculates and prints their
- //sum. Examples:
- //numbers sum numbers sum numbers sum
- //1 2 3 4 5 15 10 10 10 10 10 50 1.5 3.14 8.2 -1 0 11.84
- class Program
- {
- static void Main()
- {
- double[] numbersStrem = new double[5];
- double result = 0;
- for (int i = 0; i < numbersStrem.Length; i++)
- {
- numbersStrem[i] = double.Parse(Console.ReadLine());
- result += numbersStrem[i];
- }
- Console.WriteLine(result);
- }
- }
- //8. Numbers from 1 to n
- using System;
- //Write a program that reads an integer number n from the console and prints all the numbers in the interval [1..n],
- //each on a single line. Note that you may need to use a for-loop. Examples:
- //numbers sum numbers sum numbers sum
- //3 1
- // 2
- // 3
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i <= n; i++)
- {
- Console.WriteLine(i);
- }
- }
- }
- //9. Sum of n Numbers
- using System;
- //Write a program that enters a number n and after that enters more n numbers and calculates and prints their sum.
- //Note that you may need to use a for-loop. Examples:
- //numbers sum numbers sum numbers sum
- //3
- //20
- //60
- //10
- //90 5
- //2
- //6.5 1
- //1
- //-1
- //-0.5
- //4
- //2
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- double sum = 0;
- double[] arr = new double[n];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = double.Parse(Console.ReadLine());
- sum += arr[i];
- }
- Console.WriteLine(sum);
- Console.WriteLine();
- }
- }
- //10. Fibonacci Numbers
- sing System;
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int x = 1;
- int y = 0;
- int z = 0;
- int counter = 0;
- for (int i = 0; i < n; i++)
- {
- counter++;
- z = x + y;
- x = y;
- y = z;
- z = x + y;
- Console.WriteLine(z);
- }
- Console.WriteLine("Item: " + counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment