Skip to content

Instantly share code, notes, and snippets.

View avii-7's full-sized avatar
🚣
On a raft.

A V I I avii-7

🚣
On a raft.
View GitHub Profile
@avii-7
avii-7 / PG76.c
Last active August 26, 2021 10:47
Write a function to compute the greatest common divisor given by Euclid’s algorithm, exemplified for j = 1980, K = 1617 as follows:- 33
#include <stdio.h>
void gcd(int, int);
int main()
{
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
gcd((num1 >= num2) ? num1, num2 : num2, num1);
@avii-7
avii-7 / PG74.c
Created August 26, 2021 10:50
Write a recursive function to obtain the running sum of first 25 natural numbers
#include <stdio.h>
int sum(int);
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("\nSum of first %d number is: %d\n", num, sum(num));
@avii-7
avii-7 / PG73.c
Last active August 26, 2021 10:55
A positive integer is entered through the keyboard, write a function to find the binary equivalent of this number using recursion.
#include <stdio.h>
void binary(int);
int main()
{
int num, place = 1, bin = 0, rem;
printf("Enter a number: ");
scanf("%d", &num);
@avii-7
avii-7 / PG91.c
Last active September 1, 2021 05:52
91. Print prime numbers using sieve of Eratosthenes.
/* ------------ Print prime numbers using sieve of Eratosthenes. ------------ */
#include <stdio.h>
int main()
{
int size = 100;
int arr[size];
int i, j, k;
int half;
@avii-7
avii-7 / PG90.c
Created September 1, 2021 05:30
90. Twenty-five number are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are odd and how many are even.
#include <stdio.h>
void getData(int *, int *, int);
int main()
{
int arr[] = {11, 44, -2, 351, -1129, 34, 3, -124, 25, -9};
int size = sizeof(arr) / sizeof(arr[0]);
int count[4];
getData(arr, count, size);
@avii-7
avii-7 / PG89.c
Created September 1, 2021 05:31
Write a C program for binary search.
#include <stdio.h>
int search(int *, int, int, int);
int main()
{
int arr[] = {2, 4, 8, 16, 32, 64, 128, 256};
int size = sizeof(arr) / sizeof(arr[0]);
int find = 128;
printf("%d is found at Array index: %d.", find, search(arr, 0, (size - 1), find));
Brochette-case / Kebab case => Hello_World
lowerCamelCase / Dromedary Case => helloWorld
Pascal case / Upper Camal Case => HelloWorld
Snake case
Snake case starts with a lower case letter, and uses an underscore to separate words (although some variations start with an upper case).
Generally associated with the C programming language, although it actually started life with no particular name:
first + _ + Number = first_Number
Examples: my_func(), my_var, name, test
@avii-7
avii-7 / 1. DispatchQueueBasic.md
Last active August 9, 2024 16:04
Multi-Threading - Swift

DispatchQueue Basics

Introduction

DispatchQueue is an object that manages the execution of tasks serially or concurrently on main thread or on a background thread.

Serial Custom DispatchQueue

A custom DispatchQueue ensures that tasks are executed one at a time in the order they are added.

@avii-7
avii-7 / A10.swift
Last active September 4, 2024 19:20
Array - DSA Questions
// Print all Divisors of a given Number | A10.swift
var arr = [Int]()
// x = sqr(n)
// TimeComlexity = O(x + xlog(x) + x)
for i in 1...n where i * i <= n {
if n % i == 0 {
arr.append(i)
@avii-7
avii-7 / COW.md
Last active September 4, 2024 07:59
Swift Learnings

Swift — “copy-on-write”

"copy on write" is an optimization technique that helps in managing memory more efficiently.

It is used primarly with value types such as Array, Dictionary and String to defer the actual copying of data until it is modified. This helps in minimizing unnecessary data copying and thus improve performance.

How "copy on write" works ?

When you assign or pass a value type to another variable or function. Swift doesn't immediately creates the copy of data. Instead it shares the same underlying storage until the copy is modified.