Compare commits

4 Commits
main ... lab_0

Author SHA1 Message Date
KIX
b5f9a34935 atoi 2.0 func code 2025-11-01 06:07:58 -04:00
KIX
01f553fe4c myatoi func code 2025-11-01 04:06:04 -04:00
KIX
ba2e7c99f4 func fib code 2025-10-18 06:06:27 -04:00
KIX
e580f118a1 func sum_array code 2025-10-18 05:39:25 -04:00
8 changed files with 129 additions and 0 deletions

BIN
atoi Executable file

Binary file not shown.

34
atoi.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include <string.h>
int myatoi(char *s, int l);
int main(int argc, char **argv)
{
printf("Print your string number\n");
char s[100]; scanf("%s", s);
printf("Your converted number is %d\n", myatoi(s, strlen(s)));
return 0;
}
int myatoi(char *s, int l)
{
int result = 0;
int is_pos = 1;
for(int i=0; i < l; i++)
{
if((int)s[i]==45)
{
is_pos = -1;
}
else
{
if((int)s[i] < 48 || (int)s[i] > 57)
{
printf("Not a number\n");
result = 0;
break;
}
result = result * 10 + ((int)s[i] - 48);
}
}
result = result * is_pos;
return result;
}

BIN
atoi_2.0 Executable file

Binary file not shown.

57
atoi_2.0.c Normal file
View File

@@ -0,0 +1,57 @@
#include <stdio.h>
#include <string.h>
int myatoi(char *s, int l, int base);
int main(int argc, char **argv)
{
printf("Print your string number\n");
char s[100]; scanf("%s", s);
printf("Enter your string number base\n");
int base;
scanf("%d", &base);
printf("Your converted number is %d\n", myatoi(s, strlen(s), base));
return 0;
}
int myatoi(char *s, int l, int base)
{
int result = 0;
int is_pos = 1;
int symb;
int d;
for(int i=0; i < l; i++)
{
symb = (int)s[i];
if((int)s[i]=='-')
{
is_pos = -1;
}
else if(base <= 10)
{
if((int)s[i] < '0' || (int)s[i] > '9')
{
printf("Not a number\n");
result = 0;
break;
}
result = result * base + ((int)s[i] - '0');
}
else
{
if (symb >= '0' && symb <= '9')
{
d = symb - '0';
}
else if (symb >= 'A' && symb <= 'Z')
{
d = symb - 'A' + 10;
}
else if (symb >= 'a' && symb <= 'z')
{
d = symb - 'a' + 10;
}
result = result * base + d;
}
}
result = result * is_pos;
return result;
}

BIN
fib Executable file

Binary file not shown.

18
fib.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
int fib(int n);
int main(int argc, char **argv)
{
printf("Print number of fibanachi sum\n");
int n = 1; scanf("%d", &n);
printf("\n%dth number of fibanachi sum is: ", n);
printf("%d\n", fib(n));
return 0;
}
int fib(int n)
{
int array[n];
array[0] = 0; array[1] = 1;
for(int i = 2; i <= n; i++)
{array[i] = array[i-1] + array[i-2];}
return array[n - 1];
}

BIN
sum_array Executable file

Binary file not shown.

20
sum_array.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdio.h>
int sum(int array[], int size);
int main(int argc, char **argv)
{
int array[] = {2,2,2,2,2};
int size = sizeof(array)/sizeof(array[0]);
printf("Array size is %d\n{", size);
for(int i = 0; i < size; i++)
{printf("%d,",array[i]);}
printf("}\nResult of summing the array:%d\n", sum(array, size));
return 0;
}
int sum(int array[], int size)
{
int sum = 0;
for(int i = 0; i < size; i++)
{sum += array[i];}
return sum;
}