Skip to content

Instantly share code, notes, and snippets.

View dbc2201's full-sized avatar
💻
I may be slow to respond.

Divyansh Bhardwaj (DBC) dbc2201

💻
I may be slow to respond.
  • Chandigarh, India
  • 10:05 (UTC +05:30)
View GitHub Profile
@dbc2201
dbc2201 / variable_length_string.c
Created November 28, 2018 07:24
The length of the character array remains the same. It is an array afterall! The problem here is with the input buffer. It might take characters more than specified at the definition of array but then, your program is likely to misbehave. We need to check for this sort of errors while writing our code. Hence we use #define to define constants fo…
#include <stdio.h>
int main()
{
char a[] = "hello";
printf("%s", a);
for( int i = 0 ; i < 4 ; i++ )
{
scanf("%s", a);
printf("%s", a); // this will help you better understand the working
@dbc2201
dbc2201 / match.py
Created November 26, 2018 19:06
to match parenthesis
def match(str1):
str1 = str1.replace(" ", "") ## Omitting all the blank characters from the string
index1 = str1.index("(") ## Checking if we have the string starts with opening bracket
if index1 == 0:
diff = str1.count("(") - str1.count(")") ## Checking the difference in bracket count
if diff == 0:
print("True")
else:
print("False")
else:
@dbc2201
dbc2201 / text.py
Created November 26, 2018 19:05
to generate airport text
def generate_text(str1, str2, num1):
print("{}, go to gate {} for flight {}.".format(str1, num1, str2))
generate_text("Sam Roger", "AI221", 12)
generate_text("Tanya Patel", "AC123", 3)
@dbc2201
dbc2201 / fibonacci.py
Created November 26, 2018 19:05
a python program to print fibonacci series
def fibonacci_sequence(num1):
list1 = []
if num1 == 0:
list1 = list1
elif num1 == 1:
list1.append(0)
elif num1 == 2:
list1.extend([0, 1])
else:
list1.extend([0, 1])
@dbc2201
dbc2201 / electricity_bill.c
Created November 25, 2018 12:18
Sample Answer for Worksheet 6 Question 4
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
#define METER_CHARGE 50
double make_bill();
int main()
{
make_bill();
@dbc2201
dbc2201 / shifting.c
Created November 24, 2018 18:09
How to do bit-wise shifting in C
#include <stdio.h>
void dec_to_bin(int n);
int main()
{
int x = 4;
dec_to_bin(x);
printf("\n4 << 1\t");
dec_to_bin(x << 1);
@dbc2201
dbc2201 / bitwise1.c
Created November 22, 2018 19:46
Source Code for the Bitwise operators problem in HackerRank located here https://www.hackerrank.com/challenges/bitwise-operators-in-c/problem
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
void calculate_the_maximum(int n, int k)
{
//Write your code here.
#include <stdio.h>
int main()
{
int cp = 0, sp = 0, result = 0;
printf("Enter the CP : ");
scanf("%d", &cp);
printf("Enter the SP: ");
#include <stdio.h>
int main(void)
{
int a = 5;
if ( a > 10 )
{
printf("This was printed from inside if\n");
}
else
#include <stdio.h>
int main(void)
{
int number = 0;
int digit = 0;
int sum = 0;
printf("Enter the five digit number : ");
scanf("%d", &number);