0% found this document useful (0 votes)
26 views1 page

Program

Uploaded by

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

Program

Uploaded by

uwattoo372
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

using System.Collections.Generic;

public class Program


{
public static void Main()
{
//write your name and save into variable
string name = "Adeel Ahmad";
//count the words in my name
char[] nameCharacters =name.ToCharArray();
int wordCount = 0;
for(int c=0;c<nameCharacters.Length;c++){
if(nameCharacters[c] == ' '){
wordCount++;
}
}
Console.WriteLine("Your name contain " +(wordCount + 1)+ " words.");
//count the characters in my name
int alphabatCount = 0;
for(int c=0;c<nameCharacters.Length;c++){
if(nameCharacters[c] != ' '){
alphabatCount++;
}
}
Console.WriteLine("Your name contain " +(alphabatCount)+ "
characters.");
//write the first letter of each word
List<char> firstLetters = new List<char>();
int index =0;
for(int c=0;c<nameCharacters.Length;c++){
if(nameCharacters[c] == ' '){
index = c + 1;
continue;
}
if(c==index){
firstLetters.Add(nameCharacters[c]);
}
}
for(int r=0;r<firstLetters.Count;r++){
Console.WriteLine("Your name word " + r + " first letter is "
+firstLetters[r]);
}

}
}

You might also like