0% found this document useful (0 votes)
33 views3 pages

System : Assignment by Fasih Dawood "Countings"

This document contains C# code that counts various elements in a given string. It defines variables to track the number of uppercase letters, lowercase letters, spaces, words, vowels, consonants, and sentences. It then loops through each character in the input string, incrementing the appropriate counter variables and outputting the final counts.

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

System : Assignment by Fasih Dawood "Countings"

This document contains C# code that counts various elements in a given string. It defines variables to track the number of uppercase letters, lowercase letters, spaces, words, vowels, consonants, and sentences. It then loops through each character in the input string, incrementing the appropriate counter variables and outputting the final counts.

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment By Fasih Dawood

"Countings"

using System;

namespace ConsoleApp9

class Program

static void Main(string[] args)

string text = "This is the Cow. And a costly one";

int upcount = 0;

int lowcount = 1;

int spaces = 0;

int wrd = 1;

int vowels = 1;

int cons = 0;

int sen = 1;

for (int i = 0; i < text.Length - 1; i++)

if (text[i] > 64 && text[i] < 91)

upcount++;

else if (text[i] > 96 && text[i] < 123)

{
lowcount++;

else if (text[i].Equals(' '))

spaces++;

if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t')

wrd++;

if (text[i] == 'a' || text[i] == 'e' || text[i] == 'i' || text[i] == 'o'


|| text[i] == 'u' || text[i] == 'A' || text[i] == 'E' || text[i] == 'I' || text[i] == 'O'
|| text[i] == 'U')

vowels++;

else if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i]
<= 'Z'))

cons++;

if (text[i] == 46)

sen++;

}
}

Console.WriteLine("Upper Case Letters = {0}",upcount);

Console.WriteLine("Lower Case Letters = {0}" ,lowcount);

Console.WriteLine("Spaces = {0}",spaces);

Console.WriteLine("Words = {0}", wrd);

Console.WriteLine("Vowels = {0}", vowels);

Console.WriteLine("Consonants = {0}", cons);

Console.WriteLine("Sentences = {0}", sen);

Console.ReadKey();

You might also like