Karthikeya Boyini has Published 2193 Articles

C# program to display factors of entered number

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 11:15:47

1K+ Views

Firstly, enter the number for which you want the factors −Console.WriteLine("Enter the Number:"); n = int.Parse(Console.ReadLine());After that, loop through to find the factors −for (i = 1; i

C# program to count upper and lower case characters in a given string

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 10:52:36

1K+ Views

To count uppercase characters in a string, check the following condition −myStr[i]>='A' && myStr[i]='a' && myStr[i]

C# Program to count number of Vowels and Consonants in a string

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:35:14

830 Views

You need to check for both the vowels and consonants, but do not forget to check for both the uppercase as well lowercase.For counting vowels, check for “aeiou” characters separately i.e.if (myStr[i] == 'a' || myStr[i] == 'e' || myStr[i] == 'i' || myStr[i] == 'o' || myStr[i] == 'u' ... Read More

C# program to count the occurrences of each character

karthikeya Boyini

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++; ... Read More

C# program to count total set bits in a number

karthikeya Boyini

karthikeya Boyini

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

335 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 ... Read More

C# Program to Convert Decimal to Binary

karthikeya Boyini

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();   ... Read More

C# Program to convert first character uppercase in a sentence

karthikeya Boyini

karthikeya Boyini

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

492 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] ... Read More

C# program to check if a string is palindrome or not

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:05:35

13K+ Views

To check if a string is palindrome or not, you need to first find the reverse of the string using −Array.reverse()After that use the equals() method to match the original string with the reversed. If the result is true, that would mean the string is Palindrome.ExampleLet us try the complete ... Read More

C# Program to Check Whether the Entered Number is an Armstrong Number or Not

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:04:36

1K+ Views

For an Armstrong number, let us say a number has 3 digits, then the sum of cube of its digits is equal to the number itself.For example, 153 is equal to −1³ + 3³ + 5³To check for it using C#, check the value and find its remainder. Here “val” ... Read More

C# program to count the number of words in a string

karthikeya Boyini

karthikeya Boyini

Updated on 19-Jun-2020 09:03:23

8K+ Views

Let us first declare the string −string str = "Hello World!";Now loop through the complete string and find the whitespace or tab or newline character −while (a

Advertisements