diff --git a/c/p1.cpp b/c/p1.cpp index f1af0d7..c8ece50 100644 --- a/c/p1.cpp +++ b/c/p1.cpp @@ -14,8 +14,8 @@ void checkSum(int a[], int n, int t){ table[i][0] = true; } - for(int i=1;i<=n;i++){ - for(int j=1;j<=t;j++){ + for(int i=0;i<=n;i++){ + for(int j=0;j<=t;j++){ if(j < a[i-1]){ table[i][j] = table[i-1][j]; } diff --git a/c/p10.cpp b/c/p10.cpp index 08b90e0..9ee4767 100644 --- a/c/p10.cpp +++ b/c/p10.cpp @@ -1,5 +1,5 @@ //CPP program to implement circular linked list - +//no error #include using namespace std; struct node{ //defining the structure of the node diff --git a/c/p11.c b/c/p11.c index d6ef183..b67fd08 100644 --- a/c/p11.c +++ b/c/p11.c @@ -13,7 +13,7 @@ int isSameTree(struct TreeNode* p, struct TreeNode* q){ return 1; } if(p->val == q->val){ - return isSameTree(p->left, q->left) || isSameTree(p->right, q->right); + return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); } return 0; } diff --git a/c/p12.cpp b/c/p12.cpp index 29594f4..db9e967 100644 --- a/c/p12.cpp +++ b/c/p12.cpp @@ -1,6 +1,6 @@ //program to find the longest common subsequence (LCS) in two strings //e.g. ABCDE and AFCZE have a common subsequence of ACE - +//no errors #include using namespace std; diff --git a/c/p13.c b/c/p13.c index 753cad1..73cff9b 100644 --- a/c/p13.c +++ b/c/p13.c @@ -3,7 +3,7 @@ #include #include -int i = 0; +//int i = 0; int main(){ int i = i; @@ -17,7 +17,7 @@ int main(){ printf("%d ", a[i]); } printf("\n"); - for(i;i int romanToInt(char * s){ - int *a = (int *)malloc(strlen(s) * sizeof(int)); + int *a = (int *)malloc((strlen(s)+1) * sizeof(int)); for(int i=0;i using namespace std; - +//no error class A{ int variable; public: @@ -22,7 +22,7 @@ int A::func(){ return variable; } -int anotherFunc(A a){ +int anotherFunc(A &a){ a.variable += 3; return a.variable; } diff --git a/c/p3.cpp b/c/p3.cpp index 212f550..e99b107 100644 --- a/c/p3.cpp +++ b/c/p3.cpp @@ -14,7 +14,7 @@ vector productExceptSelf(vector& nums) { int r = 1; for(int i=nums.size()-1;i>=0;i--){ ans[i] *= r; - r = nums[i]; + r = r*nums[i]; } return ans; } diff --git a/c/p4.cpp b/c/p4.cpp index 1e83511..d7ac44f 100644 --- a/c/p4.cpp +++ b/c/p4.cpp @@ -10,10 +10,10 @@ string caesar(string s, int k, string direction){ string ans = ""; for(int i=0;i int *fun() { - int x = 5; + static int x = 5; return &x; } int main() diff --git a/c/p7.cpp b/c/p7.cpp index c5ed765..e68616d 100644 --- a/c/p7.cpp +++ b/c/p7.cpp @@ -5,7 +5,7 @@ using namespace std; int func(string s){ - int counter=-1; + int counter=0; while(counter - +#include int* filterMultiples(int* arr, int N, int* NOut, int num) { int numPrimes = 0; *NOut = 0; diff --git a/py/p1.py b/py/p1.py index b648ec0..0000282 100644 --- a/py/p1.py +++ b/py/p1.py @@ -7,6 +7,8 @@ def asterisk_tree(height,level): if level > height: return + for i in range(1,height-level+1): #for loop for adding spaces to centre the pattern + print(" ",end="") for j in range(2*level-1): print("*", end="") print() diff --git a/py/p10.py b/py/p10.py index cfc822f..de034f1 100644 --- a/py/p10.py +++ b/py/p10.py @@ -1,6 +1,8 @@ #Finding Average RGB values using the listmaker fuction to generate list of rgb values for a pixel def listmaker(r,g,b,list1=[]): + if (list1!=[]): + list1=[] list1.append(r) list1.append(g) list1.append(b) diff --git a/py/p11.py b/py/p11.py index 3d35661..590adda 100644 --- a/py/p11.py +++ b/py/p11.py @@ -1,9 +1,9 @@ # Function to convert decimal to binary number def binaryconversion(n): - print(n % 2,end = '') - if n > 1: - binaryconversion(n/2) + if n >=1: + binaryconversion(n/2) + print(n % 2,end = '') number=int(input("Enter Number: ")) binaryconversion(number) diff --git a/py/p12.py b/py/p12.py index c5b0f4d..37ab276 100644 --- a/py/p12.py +++ b/py/p12.py @@ -1,6 +1,6 @@ # Program to multiply two matrices using nested loops -A = [[1,2,3],[4,5,6],[7,8,9]] +A = [[1,2,3],[4,5,6],[7,8,9]] #no error B = [[10,11,12],[13,14,15],[16,17,18]] p = len(A) diff --git a/py/p2.py b/py/p2.py index 237c9b9..d91163d 100644 --- a/py/p2.py +++ b/py/p2.py @@ -2,8 +2,10 @@ # input- 1 -> output- [1], input- 2 -> output- [2] def add_item(item, items=[]): - items.append(item) - return items + if len(items)!=0: + items.pop(0) + items.append(item) + return items print(add_item(1)) print(add_item(2)) diff --git a/py/p3.py b/py/p3.py index c83d5ad..9a6e852 100644 --- a/py/p3.py +++ b/py/p3.py @@ -2,12 +2,11 @@ #eg: [2, 4, 6, 17, 10] -> [17, 10] def delete_starting_evens(list): - for item in list: - if list[0] % 2 == 0: - list.pop(0) - else: - break + for item in range(len(list),-1,-1): # changing to range + if list[item]%2==0: # eheck element at index is even + list.pop(item) return list -list = [2, 8, 10, 11] +list = [2, 8, 10, 11 + #changes visible print(delete_starting_evens(list)) diff --git a/py/p4.py b/py/p4.py index 2ae30d4..6c379cb 100644 --- a/py/p4.py +++ b/py/p4.py @@ -6,10 +6,10 @@ def countSort(arr): ans = [0 for i in range(len(arr))] for i in arr: count[i] += 1 - for i in range(k+1): + for i in range(1,k+1): count[i] += count[i-1] for i in range(len(arr)-1, -1, -1): - ans[count[arr[i]]] = arr[i] + ans[count[arr[i]]-1] = arr[i] count[arr[i]] -= 1 return ans diff --git a/py/p5.py b/py/p5.py index 01e1d53..0ad5959 100644 --- a/py/p5.py +++ b/py/p5.py @@ -8,10 +8,10 @@ def get_number(): val1 = input('Enter a number: ') val1 = int(val1) - str_to_print = '{:.1f}'.format(val1) + str_to_print = '{1f}'.format(val1) return str_to_print except ValueError: - get_number() + return get_number() print(get_number()) diff --git a/py/p6.py b/py/p6.py index fc571ba..0976c01 100644 --- a/py/p6.py +++ b/py/p6.py @@ -6,7 +6,7 @@ def addBinary(a: str, b: str) -> str: i = len(a) - 1 j = len(b) - 1 - while i >= 0 or j >= 0: + while i >= 0 or j >= 0 or carry!=0: if i >= 0: carry += int(a[i]) i -= 1 diff --git a/py/p7.py b/py/p7.py index ad7b53f..c773f2e 100644 --- a/py/p7.py +++ b/py/p7.py @@ -2,7 +2,7 @@ #e.g. 2->4->3 + 5->6->4 = 7->0->8 (342 + 465 = 807) # Definition for singly-linked list. -class ListNode(object): +class ListNode(object):#no error def __init__(self, val=0, next=None): self.val = val self.next = next diff --git a/py/p8.py b/py/p8.py index 4418074..03e47c3 100644 --- a/py/p8.py +++ b/py/p8.py @@ -27,7 +27,11 @@ def append_item(self, data): self.count += 1 def print_foward(self): - print(self.iter()) + current=self.head + while current: + item_val=current.data + current=current.next + print(item_val) def iter(self): # Iterate the list diff --git a/py/p9.py b/py/p9.py index 4ea1c58..c831eb5 100644 --- a/py/p9.py +++ b/py/p9.py @@ -9,9 +9,12 @@ def ispangram(str1, alphabet=string.ascii_lowercase): alphaset = list(alphabet) str = list(str1.lower()) - - # Check if all lowercase characters in the input string covers all characters in 'alphaset' - return alphaset <= str + for i in range (0,26): + if alphaset[i] not in str: + break + if i==25: + return True + return False # Print the result of checking if the string is a pangram by calling the 'ispangram' function print(ispangram('The quick brown fox jumps over the lazy dog'))