P

@praveen11

two arrays swapping using stl

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ array<int,5> a1 = {1,2,3,4,5}; array<int,5> a2 = {10,20,30,40,50}; for(int i=0;i<5;i++){ cout<<a1[i]<<" "; } cout<<"\n"; for(int i=0;i<5;i++){

stl arrays

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main() { array<int,5> a = {1,2,3}; for(int i=0;i<5;i++){ cout<<a[i]<<" "; } cout<<"\nsize of the array "<<a.size()<<"\n"<<"front and last elements: "<<a.front()<<" "<<a.ba

trace of matrix

Python
4 years ago
n = int(input()) m=[] for i in range(n): m.append([int(j) for j in input().split()]) sum=0 for i in range(n): for j in range(n): if(i==j): sum+=m[i][j] print(sum)

transpose of a matrix

Python
4 years ago
r,c = map(int,input().split()) m=[] for i in range(r): m.append([int(j) for j in input().split()]) for i in range(r): for j in range(c): print(m[j][i],end=" ") print()

sum of both diagonals

Python
4 years ago
n = int(input()) m=[] for i in range(n): m.append([int(j) for j in input().split()]) sum=0 for i in range(n): for j in range(n): if((i == j) or (i+j == n-1)): sum=sum+m[i][j] print(sum)

reading matrix2

Python
4 years ago
#this is one way to read the matrix if the input given as follows # r=3 # c=3 the matrix is 3*3 matrix # 1 2 3 # 4 5 6 # 7 8 9 r=int(input()) c=int(input()) m=[]

reading matrix1

Python
4 years ago
#this is one method to read the matrix from user when the elements of matrix #are given in separate line r=int(input()) c=int(input()) m=[] for i in range(r): a=[] for j in range(c): a.append(int(input()))

bubble sort

Python
4 years ago
l=[1,9,6,2,7,8,4] n=len(l) for i in range(n-1): for j in range(0,n-1): if(l[j]>l[j+1]): l[j],l[j+1]=l[j+1],l[j] print(l)

all substrings of a string

Python
4 years ago
s="student" n=len(s) for i in range(n): for j in range(i+1,n+1): print(s[i:j])

lcm of two numbers

Python
4 years ago
def gcd(a,b): if(a==0): return b return gcd(b%a,a) def lcm(a,b): return (a/(gcd(a,b))*b a,b=map(int,input().split())

reading large inputs

Python
4 years ago
#here we take a,b as large integers like a=12345678909087654321 b=9876543211234567890 a,b = map(int,input().split()) print(a+b) print(a*b)

reading multiple input in a single line

Python
4 years ago
#reading multiple input in a single line a,b = map(int,input().split()) print(a+b)