Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rahulrajkwalke.mct2021 #355

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
8 changes: 4 additions & 4 deletions c/p13.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
#include <stdio.h>
#include <stdlib.h>

int i = 0;


int main(){
int i = i;
int i = 0;
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {7, 8, 9, 10, 11, 12, 13};

int n = sizeof(a)/sizeof(a[0]);
int m = sizeof(b)/sizeof(b[0]);

for(int i=0;i<n;i++);{
for(i;i<n;i++){
printf("%d ", a[i]);
}
printf("\n");
for(i;i<m;i++){
for(i=0;i<m;i++){
printf("%d ", b[i]);
}
}
3 changes: 2 additions & 1 deletion c/p14.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include<string.h>

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<strlen(s);i++){
switch(s[i]){
case 'I': a[i] = 1; break;
Expand All @@ -15,6 +15,7 @@ int romanToInt(char * s){
case 'C': a[i] = 100; break;
case 'D': a[i] = 500; break;
case 'M': a[i] = 1000; break;
default: a[i] =0;break;
}
}
int num=0;
Expand Down
7 changes: 4 additions & 3 deletions c/p15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ using namespace std;
void Upper(char *word) {
for(int k = 0; word[k]; k ++)
word[k] = toupper(word[k]);
Check(word);
cout << Check(word) << endl;
}

int Check(char *S) {
for(int k = 0, v = 0; S[k]; k++)
int v=0;
for(int k = 0; S[k]; k++)
switch(S[k]) {
case A:
case E:
Expand All @@ -30,7 +31,7 @@ int main() {
cout << Check(str) << endl;
cout << "Type yes to continue, no to exit.";
cin >> next;
} while(strcmp(next, "yes"));
} while(strcmp(next, "no")!=0);

return 0;
}
2 changes: 1 addition & 1 deletion c/p2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int A::func(){
return variable;
}

int anotherFunc(A a){
int anotherFunc(A& a){
a.variable += 3;
return a.variable;
}
Expand Down
2 changes: 1 addition & 1 deletion c/p3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vector<int> productExceptSelf(vector<int>& nums) {
int r = 1;
for(int i=nums.size()-1;i>=0;i--){
ans[i] *= r;
r = nums[i];
r*= nums[i];
}
return ans;
}
Expand Down
2 changes: 1 addition & 1 deletion c/p5.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ void main(){
int a=10;
int *ptr = &a;

*ptr++;
(*ptr)++;
printf("%d", *ptr);
}
8 changes: 6 additions & 2 deletions c/p6.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
#include<stdio.h>
int *fun()
{
int x = 5;
return &x;
int *ptr=(int*)malloc(sizeof(int));
if(ptr==NULL){
exit(1);}
*ptr=5;
return ptr;
}
int main()
{
int *ptr = fun ();
printf ("%d", *ptr);
free(ptr);
return 0;
}
4 changes: 2 additions & 2 deletions c/p7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using namespace std;

int func(string s){
int counter=-1;
while(counter<s.length())
int counter=0;
while(counter < s.length())
counter++;
return counter;
}
Expand Down
4 changes: 1 addition & 3 deletions py/p1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
def asterisk_tree(height,level):
if level > height:
return
for j in range(2*level-1):
print("*", end="")
print()
print(" "*(height-level)+"*"*((2*level)-1))
asterisk_tree(height, level + 1)

n=int(input("Enter height of tree : "))
Expand Down
3 changes: 2 additions & 1 deletion py/p10.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Finding Average RGB values using the listmaker fuction to generate list of rgb values for a pixel

def listmaker(r,g,b,list1=[]):
def listmaker(r,g,b):
list1=[]
list1.append(r)
list1.append(g)
list1.append(b)
Expand Down
12 changes: 8 additions & 4 deletions py/p11.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Function to convert decimal to binary number

def binaryconversion(n):
print(n % 2,end = '')
def binaryconversion(n,l=[]):
l.append(n%2)
if n > 1:
binaryconversion(n/2)

binaryconversion(n//2)
else:
g = ''
for i in l[::-1]:
g +=str(i)
print(g)
number=int(input("Enter Number: "))
binaryconversion(number)
print()
3 changes: 2 additions & 1 deletion py/p2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#program to print an input as the only member of an array everytime the function is called
# input- 1 -> output- [1], input- 2 -> output- [2]

def add_item(item, items=[]):
def add_item(item):
items=[]
items.append(item)
return items

Expand Down
11 changes: 5 additions & 6 deletions py/p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return list
lst = []
for i in lst:
if i%2!=0:
lst.append(i)
return lst

list = [2, 8, 10, 11]
print(delete_starting_evens(list))
3 changes: 1 addition & 2 deletions py/p5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ def get_number():
try:
val1 = int(val1)
while val1 < 1 or val1 > 10:
val1 = input('Enter a number: ')
val1 = int(val1)
raise ValueError

str_to_print = '{:.1f}'.format(val1)
return str_to_print
Expand Down
6 changes: 4 additions & 2 deletions py/p9.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
def ispangram(str1, alphabet=string.ascii_lowercase):
alphaset = list(alphabet)

str = list(str1.lower())
str = list(set(str1.lower()))
str.remove(" ")
str.sort()

# Check if all lowercase characters in the input string covers all characters in 'alphaset'
return alphaset <= str
return alphaset == str

# 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'))