תוכן עניינים

1. מחרוזת אותיות גדולות לקטנות

כיתבו תוכנית המקבלת כקלט מחרוזת של אותיות גדולות וממירה אותה לאותיות קטנות. למשל: עבור הקלט MOON הפלט יהיה moon.

2. מחרוזת אותיות גדולות לקטנות (ללא פעולות עזר)

כיתבו תוכנית המקבלת כקלט מחרוזת של אותיות גדולות וממירה אותה לאותיות קטנות. מותר להשתמש באותיות בלבד, בלי להיעזר בפעולות נוספות. למשל: עבור הקלט MOON הפלט יהיה moon.

3. האם מילה מופיעה במחרוזת

כיתבו תוכנית שתקלוט מהמשתמש שתי מחרוזות. האחת היא מילה והשנייה היא משפט. התוכנית תבדוק אם המילה מופיעה בתחילת המחרוזת ותדפיס הודעה בהתאם.

4. האם תו מופיע במחרוזת

כיתבו תוכנית שתקלוט מהמשתמש תו בודד char וכן תקלוט גם מחרוזת. התוכנית תדפיס True אם התו מופיע במחרוזת בין 1 ל-3 פעמים, אחרת יודפס False.

5. ספירת מספר האותיות הקטנות במחרוזת

כתבו תוכנית שתקלוט מהמשתמש מחרוזת. התוכנית תספור כמה אותיות קטנות (a–z) יש במחרוזת ותדפיס את הכמות.

6. האם כל האותיות במחרוזת הן גדולות

כתבו תוכנית שתקלוט מחרוזת ותבדוק האם כל התווים בה הן אותיות גדולות בלבד (A–Z). אם כן, התוכנית תדפיס True. אחרת תדפיס False.

7. הדפסת מחרוזת ללא רווחים

כתבו תוכנית שתקלוט מחרוזת ותדפיס אותה מחדש, אך בלי רווחים בכלל (לא רווחים בתחילה, באמצע או בסוף).

8. ספירת תווים מסוימים במחרוזת

כתבו תוכנית שתקלוט מחרוזת וכן תקלוט תו בודד. לאחר מכן, התוכנית תספור כמה פעמים התו מופיע במחרוזת ותדפיס את הכמות.

9. האם המחרוזת כוללת רק ספרות

כתבו תוכנית שתקלוט מחרוזת ותבדוק אם כל התווים בה הם ספרות בלבד (0–9). אם כן – תדפיס True, אחרת – False.

10. הדפסת מחרוזת במהופך

כתבו תוכנית שתקלוט מחרוזת ותדפיס אותה הפוך. לדוגמה: עבור הקלט hello יודפס olleh.

פתרונות

				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter uppercase string: ");
        string input = Console.ReadLine();

        for (int i = 0; i < input.Length; i++)
        {
            // Convert uppercase (A-Z) to lowercase (a-z)
            if (input[i] >= 'A' && input[i] <= 'Z')
            {
                char lower = (char)(input[i] + 32);
                Console.Write(lower);
            }
            else
            {
                Console.Write(input[i]); // keep as-is
            }
        }

        Console.WriteLine();
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter uppercase letters only: ");
        string input = Console.ReadLine();

        for (int i = 0; i < input.Length; i++)
        {
            // Assumes all letters are uppercase
            char lower = (char)(input[i] + 32);
            Console.Write(lower);
        }

        Console.WriteLine();
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter word: ");
        string word = Console.ReadLine();
        Console.Write("Enter sentence: ");
        string sentence = Console.ReadLine();

        bool match = true;

        if (word.Length > sentence.Length)
            match = false;
        else
        {
            for (int i = 0; i < word.Length; i++)
            {
                if (word[i] != sentence[i])
                {
                    match = false;
                    break;
                }
            }
        }

        if (match)
            Console.WriteLine("The word appears at the beginning.");
        else
            Console.WriteLine("The word does not appear at the beginning.");
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a character: ");
        char ch = Console.ReadLine()[0];

        Console.Write("Enter a string: ");
        string text = Console.ReadLine();

        int count = 0;

        for (int i = 0; i < text.Length; i++)
        {
            if (text[i] == ch)
                count++;
        }

        if (count >= 1 && count <= 3)
            Console.WriteLine("True");
        else
            Console.WriteLine("False");
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        int count = 0;

        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] >= 'a' && input[i] <= 'z')
            {
                count++;
            }
        }

        Console.WriteLine("Number of lowercase letters: " + count);
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        bool allUppercase = true;

        for (int i = 0; i < input.Length; i++)
        {
            if (!(input[i] >= 'A' && input[i] <= 'Z'))
            {
                allUppercase = false;
                break;
            }
        }

        Console.WriteLine(allUppercase);
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        string result = "";

        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] != ' ')
            {
                result += input[i];
            }
        }

        Console.WriteLine("String without spaces: " + result);
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        
        Console.Write("Enter a character: ");
        char ch = Console.ReadLine()[0];

        int count = 0;

        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == ch)
            {
                count++;
            }
        }

        Console.WriteLine("Character appears " + count + " times.");
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        bool onlyDigits = true;

        for (int i = 0; i < input.Length; i++)
        {
            if (!(input[i] >= '0' && input[i] <= '9'))
            {
                onlyDigits = false;
                break;
            }
        }

        Console.WriteLine(onlyDigits);
    }
}
				
			
				
					using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        string reversed = "";

        for (int i = input.Length - 1; i >= 0; i--)
        {
            reversed += input[i];
        }

        Console.WriteLine("Reversed string: " + reversed);
    }
}