Skip to content

Commit 8383049

Browse files
author
nukala.akhil
committed
First commit
0 parents  commit 8383049

File tree

176 files changed

+1341343
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+1341343
-0
lines changed

DEMO_file

318 KB
Binary file not shown.

DEMO_file.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main(void)
4+
{
5+
6+
char ch = 'A';
7+
fprintf(stderr, "%c\n", ch);
8+
}

cs50

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5b7ac15ef81a4ee04455c1881923aa81c0439eff

finance.db

Whitespace-only changes.

fprinf_DEMO.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main0(void)
4+
{
5+
6+
char ch = 'A';
7+
fprintf(stderr, "%c\n", ch);
8+
}

pointers

321 KB
Binary file not shown.

pointers.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdio.h>
2+
#include<stdlib.h>
3+
4+
void swap(int *x, int *y);
5+
6+
typedef struct node
7+
{
8+
int n;
9+
struct node *ptr;
10+
}
11+
node;
12+
13+
int main(void)
14+
{
15+
int *x;
16+
int *y;
17+
node *root = malloc(sizeof(node));
18+
node *trav = root;
19+
if (trav -> ptr == NULL)
20+
{
21+
printf("YOOO NULLL");
22+
}
23+
x = malloc(sizeof(int));
24+
y = malloc(sizeof(int));
25+
*x = 5;
26+
*y = 6;
27+
swap(x, y);
28+
printf("%i, %i\n", *x, *y);
29+
printf("%lu\n", sizeof(char *));
30+
char *filename = malloc(sizeof(char *));
31+
//sprintf(filename, "%03i.jpg", 5);
32+
// FILE *img = fopen(filename, "w");
33+
int *buffer = malloc(sizeof(int));
34+
*buffer = 10;
35+
fwrite(buffer, 1, 1, img);
36+
free(x);
37+
free(y);
38+
39+
}
40+
41+
void swap(int *x, int *y)
42+
{
43+
int temp = *x;
44+
*x = *y;
45+
*y = temp;
46+
}

pset1/credit

324 KB
Binary file not shown.

pset1/credit.c

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <stdio.h>
2+
#include <cs50.h>
3+
4+
bool validNumDigits(long long num);
5+
int getSum(long long num);
6+
7+
int main(void)
8+
{
9+
printf("Number: ");
10+
long long num = get_long_long();
11+
12+
int total = 0;
13+
if (validNumDigits(num))
14+
{
15+
total = getSum(num);
16+
if (total % 10 == 0)
17+
{
18+
while (num > 100)
19+
{
20+
num = num/10;
21+
}
22+
if (num == 34 || num == 37)
23+
{
24+
printf("AMEX\n");
25+
}
26+
else if (num > 50 && num < 56)
27+
{
28+
printf("MASTERCARD\n");
29+
}
30+
else if ( (num/10) == 4)
31+
{
32+
printf("VISA\n");
33+
}
34+
else
35+
{
36+
printf("INVALID\n");
37+
}
38+
}
39+
else
40+
{
41+
printf("INVALID\n");
42+
}
43+
44+
}
45+
else
46+
{
47+
printf("INVALID\n");
48+
}
49+
}
50+
51+
bool validNumDigits(long long num)
52+
{
53+
int count = 0;
54+
while (num > 0)
55+
{
56+
count++;
57+
num = num/10;
58+
}
59+
if (count == 15 || count == 16 || count == 13)
60+
{
61+
return true;
62+
}
63+
else
64+
{
65+
return false;
66+
}
67+
}
68+
69+
int getSum(long long num)
70+
{
71+
int sum = 0;
72+
int count = 1;
73+
while (num > 0)
74+
{
75+
if (count % 2 == 0)
76+
{
77+
int rem = num % 10;
78+
switch(rem)
79+
{
80+
case 1:
81+
case 2:
82+
case 3:
83+
case 4:
84+
sum += (rem * 2);
85+
break;
86+
case 5:
87+
sum += 1;
88+
break;
89+
case 6:
90+
sum += 3;
91+
break;
92+
case 7:
93+
sum += 5;
94+
break;
95+
case 8:
96+
sum += 7;
97+
break;
98+
case 9:
99+
sum += 9;
100+
break;
101+
}
102+
}
103+
else
104+
{
105+
int rem = num % 10;
106+
sum += rem;
107+
}
108+
num = num/10;
109+
count++;
110+
}
111+
return sum;
112+
}

pset1/hello

318 KB
Binary file not shown.

pset1/hello.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(void)
4+
{
5+
printf("Hello, world!\n");
6+
}

pset1/mario

319 KB
Binary file not shown.

pset1/mario.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
#include <cs50.h>
3+
4+
int main(void)
5+
{
6+
printf("Enter a non-negative integer < 24: ");
7+
int height = get_int();
8+
while (height > 23 || height < 0)
9+
{
10+
printf("Enter a non-negative integer < 24: ");
11+
height = get_int();
12+
}
13+
for (int i = 0; i < height; i++)
14+
{
15+
for (int k = height-1; k > i; k--)
16+
{
17+
printf(" ");
18+
}
19+
for (int j = 0; j <= i; j++)
20+
{
21+
printf("#");
22+
}
23+
printf(" ");
24+
for (int j = 0; j <= i; j++)
25+
{
26+
printf("#");
27+
}
28+
29+
printf("\n");
30+
}
31+
32+
33+
}

pset1/water

318 KB
Binary file not shown.

pset1/water.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <cs50.h>
3+
4+
int main(void)
5+
{
6+
printf("Minutes: ");
7+
int min = get_int();
8+
printf("Bottles: %i\n", min * 12);
9+
}

pset2/caesar/caesar

324 KB
Binary file not shown.

pset2/caesar/caesar.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <ctype.h>
4+
#include <cs50.h>
5+
#include <string.h>
6+
7+
int main(int argc, string argv[])
8+
{
9+
if (argc != 2)
10+
{
11+
printf("wrong no of arguments\n");
12+
return 1;
13+
}
14+
int key = atoi(argv[1]);
15+
key = key % 26;
16+
printf("plaintext: ");
17+
string s = get_string();
18+
printf("ciphertext: ");
19+
for (int i = 0, n = strlen(s); i < n; i++)
20+
{
21+
if (isupper(s[i]))
22+
{
23+
printf("%c", (s[i] - 'A' + key ) % 26 + 'A');
24+
}
25+
else if (islower(s[i]))
26+
{
27+
printf("%c", (s[i] - 'a' + key ) % 26 + 'a');
28+
}
29+
else
30+
{
31+
printf("%c", s[i]);
32+
}
33+
}
34+
printf("\n");
35+
}

pset2/initials

319 KB
Binary file not shown.

pset2/initials.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <cs50.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
6+
int main(void)
7+
{
8+
string s = get_string();
9+
bool flag = true;
10+
for (int i = 0, n = strlen(s); i < n; i++)
11+
{
12+
if ( ('a' <= s[i] && s[i] <= 'z' ) || ('A' <= s[i] && s[i] <= 'Z' ) )
13+
{
14+
if (flag)
15+
{
16+
printf("%c", toupper(s[i]));
17+
flag = false;
18+
}
19+
}
20+
else if (s[i] == ' ' && i > 0)
21+
{
22+
flag = true;
23+
}
24+
}
25+
printf("\n");
26+
}

pset2/vigenere/vigenere

326 KB
Binary file not shown.

pset2/vigenere/vigenere.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <ctype.h>
4+
#include <cs50.h>
5+
#include <string.h>
6+
7+
int main(int argc, string argv[])
8+
{
9+
if (argc != 2)
10+
{
11+
printf("wrong no of arguments\n");
12+
return 1;
13+
}
14+
for (int i = 0, n = strlen(argv[1]); i < n; i++)
15+
{
16+
if (!(isalpha(argv[1][i])))
17+
{
18+
printf("wrong key\n");
19+
return 1;
20+
}
21+
}
22+
int index = 0;
23+
24+
string key = argv[1];
25+
int keylen = strlen(key);
26+
printf("plaintext: ");
27+
string s = get_string();
28+
printf("ciphertext: ");
29+
int shift;
30+
for (int i = 0, n = strlen(s); i < n; i++)
31+
{
32+
if (isupper(s[i]))
33+
{
34+
if (index >= keylen)
35+
{
36+
index = 0;
37+
}
38+
39+
if (isupper(key[index]))
40+
{
41+
shift = key[index] - 'A';
42+
}
43+
else
44+
{
45+
shift = key[index] - 'a';
46+
}
47+
printf("%c", (s[i] - 'A' + shift ) % 26 + 'A');
48+
49+
index++;
50+
}
51+
else if (islower(s[i]))
52+
{
53+
if (index >= keylen)
54+
{
55+
index = 0;
56+
}
57+
if (isupper(key[index]))
58+
{
59+
shift = key[index] - 'A';
60+
}
61+
else
62+
{
63+
shift = key[index] - 'a';
64+
}
65+
printf("%c", (s[i] - 'a' + shift ) % 26 + 'a');
66+
67+
index++;
68+
}
69+
else
70+
{
71+
printf("%c", s[i]);
72+
}
73+
}
74+
printf("\n");
75+
}

pset3/fifteen/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fifteen: fifteen.c
2+
clang -ggdb3 -O0 -std=c11 -Wall -Werror -o fifteen fifteen.c -lcs50 -lm
3+
4+
clean:
5+
rm -f *.o a.out core fifteen log.txt

pset3/fifteen/fifteen

17.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)