From ca3ed89053b93e91a84392a5f30e1986893891bd Mon Sep 17 00:00:00 2001 From: Siddhant-2312 <57628265+Siddhant-2312@users.noreply.github.com> Date: Sun, 24 Nov 2019 00:00:22 +0530 Subject: [PATCH] Update Software_Developer.txt --- Software_Developer.txt | 118 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/Software_Developer.txt b/Software_Developer.txt index bf7098f..ba25ea9 100644 --- a/Software_Developer.txt +++ b/Software_Developer.txt @@ -18,6 +18,19 @@ e-d-c-b-a-b-c-d-e ----e-d-c-d-e---- ------e-d-e------ --------e-------- +code: +import string + +alpha = string.ascii_lowercase + +num = int(input()) + +def srange(N): + return list(range(N))+list(range(N-2,-1,-1)) + +for i in srange(num): + print('-'.join([alpha[num-j-1] for j in srange(i+1)]).center(4*(num-1)+1,'-')) + Question 1: Understand the pattern and write the code accordingly. n = 4 @@ -33,6 +46,109 @@ n = 5 ****10011012019020021 ******13014017018 ********15016 + code: + #include + +void main() { + int i,j,sum=0,n,k=0,s=17,q,r,x; + + n=10; + scanf("%d",&x); + q=2*x; + if(x==4){ + s=17; +for (i=1;i<=x;i++){ + for (j=1;j<=x;j++){ + if(j>=i){ + sum=sum+n; + printf("%d",sum);} + else if(i>j){ + printf("**");} + else{ + printf(" ");} + } + for (r=x+1;r<=q;r++){ + + if(q==(r)){ + printf("%d",(s+(r-(x)))-1); + } + + else{ + printf("%d0",(s+(r-(x)))-1);} + + + + } +k++; +s=s-((q-x)-1); +q=q-1; + printf("\n"); + } + } + else + { + s=26; + for (i=1;i<=x;i++){ + for (j=1;j<=x;j++){ + if(j>=i){ + sum=sum+n; + printf("%d",sum);} + else if(i>j){ + printf("**");} + else{ + printf(" ");} + } + for (r=x+1;r<=q;r++){ + + if(q==(r)){ + printf("%d",(s+(r-(x)))-1); + } + + else{ + printf("%d0",(s+(r-(x)))-1);} + + + + } +k++; +s=s-((q-x)-1); +q=q-1; + printf("\n"); + } + } +} + Question 2: Write a function which takes n as input and returns the corresponding nth fibonacci number. NOTE: You have to use recursion. - You have to make sure program works even for 100th fibonacci number. \ No newline at end of file + You have to make sure program works even for 100th fibonacci number. + code: +MAX = 1000 + + fibonacci code: +f = [0] * MAX + +def fib(n) : + # Base cases + if (n == 0) : + return 0 + if (n == 1 or n == 2) : + f[n] = 1 + return (f[n]) + + if (f[n]) : + return f[n] + + if( n & 1) : + k = (n + 1) // 2 + else : + k = n // 2 + if((n & 1) ) : + f[n] = (fib(k) * fib(k) + fib(k-1) * fib(k-1)) + else : + f[n] = (2*fib(k-1) + fib(k))*fib(k) + + return f[n] + +n = int(input()) +print(fib(n)) +