Featured Posts

Start Your Journey with Linux Command Line

Image
🐧 Mastering the Linux Command Line Kali Linux Command Line Your Complete Guide: From Beginner to Confident User 35+ Essential Commands Covered with Real Examples Whether you're a developer, system administrator, or just curious about Linux, mastering the command line is an essential skill that will dramatically boost your productivity. This comprehensive guide breaks down the most critical Linux commands into logical categories with real, copy-paste examples you can try right now. We'll progress from basic file navigation to advanced system administration and network analysis, giving you a clear path to command-line proficiency. 📁 Section 1: The Core Workflow - Navigation Essentials Every Linux session follows a natural flow: figure out where you are, see what's around you, move to where you need to be, and then work with files. Let's master each step. pwd → ls ...

cs50 Week 2 Problem Set 2 Readability Solution

CS50 Week 2 Problem Set 2 Readability

Cs50 Problem set 2 Readability Solution
Problem Set 2 - Readability

In coding, problems have different ways to get to the solution. Below code is one way. Soon, we will be posting different codes.

** Remember:

Try to change some things in the code before submitting it in order to avoid being rejected as Harvard academic honesty.

The Solution:

#include <cs50.h>

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <ctype.h>

int main(void)

{

    // inintiate needed variables

    string text = get_string("TEXT: ");

    int letters = 0;

    int words = 1;

    int sentences = 0;

    for (int i = 0; i < strlen(text); i++)

    {

        if (isalpha(text[i]))

        {

            letters++;

        }

        else if (text[i] == ' ')

        {

            words++;

        }

        else if (text[i] == '.' || text[i] == '?' || text[i] == '!')

        {

            sentences++;

        }

    }


    // Initiate variables needed to construct the formula

    float L = (float) letters / (float) words * 100;

    float S = (float) sentences / (float) words * 100;

    int index = round(0.0588 * L - 0.296 * S - 15.8);


    if (index < 1)

    {

        printf("Before Grade 1\n");

    }

    else if (index > 16)

    {

        printf("Grade 16+\n");

    }

    else

    {

        printf("Grade %i\n" , index);

    }

}




Comments