Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

/usr/include

#include <cs50.h>
#include <stdio.h>

int main(void)
{
string name = get_string ("what's your name? ");
printf("hello, %\n", name); (make hello =
clang -o hello hello.c -lcs50);
}

=) Qua trinh xu ly giu lieu ben trong may tinh: Xu ly he nhi phan de may tinh hieu
duoc ngon ngu.
1. Preprocessing
2. Compiling
3. Assembling
4. Linking

Fix bug
$ debug50 ./buggy0
looks like you've changed your code. Recompile and then re-run debug5
=)
$ make buggy0
$ debug50 ./buggy0

Arrays
#include <cs50.h>
#include <stdio.h>

int main(void)
{
int scores[3]
for (int i = 0; i < 3; i++)
{
scores[i] = get_int("scores: ");
}

printf("Average: %f\n";(scores[0] + scores[1] + scores[2]) / (float) 3);


}
TERMINAL
# make buggy0
# ./buggy0
# scores[0]: 72
# scores[1]: 73
# scores[2]: 33
Average: 59.333332...

float average(int array[])


return (array[0] + array[1] + array[2]) / 3.0;

float average(int array[])


{
int sum = 0;
for (int i = 0; i < N; i++)
{
sum = sum + array[i];
}
return sum / (float) N;
}
(*)Char:
#include <cs50.h>
#include <stdio.h>

int main(void)
{
Char a = "H";
Char b = "I";
Char c = "!";
printf(% % %\n; a, b, c); (%i %i %i\n, a, b ,c) =) $make hi_ $./hi $ 72 73
33_$ (%i is the number of type)
}
TERMINAL
$ make hi
$ ./hi
HI!
$

String:
#include <cs50.h>
#include <stdio.h>

int main(void)
{
string s = "HI!"'; or string words[2];
string t = "BYE!"; words[0] = "HI!";
words[1] = "BYE!";
printf("%s\n", s); printf("%s\n", words[0]);
printf("%s\n", t); printf("%s\n", words[1]);
}
TERMINAL
$ make hi
$ ./hi
HI!
BYE!
$

(*) STRLEN: this is length of sentence


#include <cs50.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
string name = get_string("what's your name? ");
int n = strlen(name);
printf("%i\n", n);
}
TERMINAL
$ make length
$ ./length
$ what's your name? David
$ 5 (this is the sentence of David )
$

(*) CTYPE.H this is turn on or turn off CAPLOCK! uppercase.


#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
string s = get_string("Before: ");
printf("After: ");
for (int i = 0; i < strlen(s); i++);
{
if (s[i] >= 'a' && s[i] <= 'z') or if (islower(s[i]));
{
printf("%c", s[i] - 32); or printf("%c", toupper(s[i])); =) this distance
of A to a is 32 bit = 8 byte
}
else
{
printf("%c", s[i]);
}
printf("\n");
}
=) Do faster more than: use only printf("%c", toupper(s[i])); and you have
wonderful result. Everything now you just
understand why? program this here? why?... just understand why?
}

Okay tonight we study to here! Good job man! See you a later! Good night! Thanks
you.

Lesson is continue in 30 minutes! 9:50 pm.

(*) GREET C

#include <cs50.h>
#include <stdio.h>

int main(int argc, string argv[])


{
if (argc == 2)
{
printf("hello, %s\n", argv[1]);
}
else
{
printf("hello, world\n");
}
}

(*) EXIT STATUS:

#include <cs50.h>
#include <stdio.h>

int main(int argc, string argv[])


{
if (argc !=2)
{
printf("Mission command-line argument\n");
}
else
{
printf("hello, %s\n", argv[1]);
}
}
TERMINAL
$ make status
$ ./status
Missing command-line argument
$ ./status David
hello, David
$

(*) ECHO $?
(+) CRYPTOGRAPHY this is the code for hidden or secret messenger
(+) ENCRYPTION nt
(+) DECRYPTION nt

You might also like