Count Occurrences of Each Character in C#

karthikeya Boyini
Updated on 19-Jun-2020 09:33:20

32K+ Views

Firstly, set the string −string str = "Website"; Console.WriteLine("String: "+str);Check for every character in the string and increment a variable that would count the number of occurrences of that character −for (int j = 0; j < str.Length; j++) {    if (str[0] == str[j]) {       cal++;    } }ExampleYou can try to run the following code to count the occurrences of each character.Live Demousing System; public class Demo {    public static void Main() {       string str = "Website";       Console.WriteLine("String: "+str);       while (str.Length > 0) {   ... Read More

C# Program to Count Total Bits in a Number

Samual Sam
Updated on 19-Jun-2020 09:32:32

593 Views

Let us say the number we have is 12. We have declared and initialized a uint variable by assigning a decimal literal,uint val = 12;The binary representation of 12 is −1100The bits above is 4, therefore to find the total bits, use the Math.log() method −uint res = (uint)Math.Log(val , 2.0) + 1;ExampleYou can try to run the following code to count total bits in a number.Live Demousing System; public class Demo {    public static void Main() {       uint val = 12; // 1100 in binary       uint res = (uint) Math.Log(val, 2.0) + 1;       // 1100 has 4 bits       Console.WriteLine("Total bits: " + res);    } }OutputTotal bits: 4

Count Total Set Bits in a Number using C#

karthikeya Boyini
Updated on 19-Jun-2020 09:31:40

352 Views

The number for our example is 11 i.e. binary −1101The total set bits are 3 in 1101; to find it, use a loop till it’s not equal to 0. Here, our num is 11 i.e. decimal −while (num>0) {    cal += num & 1;    num >>= 1; }ExampleTo count total set bits in a number, use the following code.Live Demousing System; public class Demo {    public static void Main() {       int cal = 0;       // Binary is 1011       int num = 11;       while (num>0) {          cal += num & 1;          num >>= 1;       }       // 1 bits in 1101 are 3       Console.WriteLine("Total bits: "+cal);    } }OutputTotal bits: 3

Convert Digits to Words in C#

Samual Sam
Updated on 19-Jun-2020 09:29:32

4K+ Views

Firstly, declare the words from 0 to 9 −// words for every digits from 0 to 9 string[] digits_words = { "zero", "one", "two",    "three", "four", "five",    "six", "seven", "eight",    "nine" };The following are the digits to be converted to words −// number to be converted into words val = 4677; Console.WriteLine("Number: " + val);Use the loop to check for every digit in the given number and convert into words −do {    next = val % 10;    a[num_digits] = next;    num_digits++;    val = val / 10; } while(val > 0);ExampleYou can try to ... Read More

C# Program to Convert Decimal to Binary

karthikeya Boyini
Updated on 19-Jun-2020 09:28:41

1K+ Views

Let’ s say you have set the decimal to be −decVal = 34; Console.WriteLine("Decimal: {0}", decVal);Use the ToString() method for the values you get as a binary number for the decimal value −while (decVal >= 1) {    val = decVal / 2;    a += (decVal % 2).ToString();    decVal = val; }Now set a new empty variable to display the binary number using a loop −string binValue = "";ExampleYou can try to run the following code to convert decimal to binary in C#.Live Demousing System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplication {     ... Read More

Convert Fahrenheit to Celsius in C#

Samual Sam
Updated on 19-Jun-2020 09:28:03

3K+ Views

Firstly, set the Fahrenheit temperature −double fahrenheit = 97; Console.WriteLine("Fahrenheit: " + fahrenheit);Now convert it into Celsius −celsius = (fahrenheit - 32) * 5 / 9;ExampleYou can try to run the following code to convert Fahrenheit to Celsius.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          double celsius;          double fahrenheit = 97;          Console.WriteLine("Fahrenheit: " + fahrenheit);          celsius = (fahrenheit - 32) * 5 / 9;          Console.WriteLine("Celsius: " + celsius);          Console.ReadLine();       }    } }OutputFahrenheit: 97 Celsius: 36.1111111111111

Convert First Character to Uppercase in a Sentence Using C#

karthikeya Boyini
Updated on 19-Jun-2020 09:27:24

504 Views

Let us say the following is your string −String str = "Welcome to our website!";Create a char array of the string included above using the ToCharArray() method:char []ch = str.ToCharArray();To convert the first character to uppercase −if (ch[i] >= 'a' && ch[i] = 'a' && val[i] = 'A' && val[i]

Moving Object Databases

Alex Onsman
Updated on 19-Jun-2020 09:26:24

905 Views

Moving objects are those whose position changes frequently over a period of time. Conventional databases don't know how to handle this scenario, as they assume the data objects are stationaryIn this case, we use moving object databases. These databases can store information about moving objects and allow querying on them.For example- The location of nearest taxis for a particular customer can be found using querying on moving object databases.The approaches used in handling moving object databases are:Location ManagementThe current locations of the objects are saved in the database and estimations are made on their near future positions. This information is ... Read More

Mandatory and Optional Participation

Alex Onsman
Updated on 19-Jun-2020 09:21:42

5K+ Views

Mandatory and optional participation are observed in E-R models between 2 different entities.Mandatory ParticipationIn the mandatory participation, for every instance of entity A, there must exist an instance of entity B and vice versa.An example of Mandatory participation would be relationship between mother and child. The child entity would exist only if there were a mother and similarly a mother would exist only if there were a childOptional participationIn optional participation, it is not necessary for all the instances of the entity to participate in a relationship. It may be that the number of instances participating for a particular entity ... Read More

Examples of E-R Model

Alex Onsman
Updated on 19-Jun-2020 09:06:54

17K+ Views

ER model is used to represent real life scenarios as entities. The properties of these entities are their attributes in the ER diagram and their connections are shown in the form of relationships.Some examples of ER model are −Hospital ER ModelThis is an ER model of a Hospital. The entities are represented in rectangular boxes and are Patient, Tests and Doctor.Each of these entities have their respective attributes which are −Patients - ID(primary key), name, age, visit_dateTests- Name(primary key), date, resultDoctor- ID(primary key), name, specializationThe relationships between different entities are represented by a diamond shaped box.Company ER ModelThe entities in this ... Read More

Advertisements