P

@praveen11

Printing Pattern Using Loops

C
4 years ago
#include <stdio.h> #define min(a, b) ((a) < (b) ? (a) : (b)) int main() { int n; scanf("%d", &n); int len = n * 2 - 1; for(int i = 0; i < len; i++)

Calculate the Nth term

C
4 years ago
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> //Complete the following function. int find_nth_term(int n, int a, int b, int c) { if(n==1) return a; else if(n==2)

Students Marks Sum

C
4 years ago
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int marks_summation(int* marks, int number_of_students, char gender) { int sum = 0; for (int i = (gender == 'b' ? 0 : 1); i < number_of_students; i = i + 2) sum += *(marks + i);

Bitwise Operators

C
4 years ago
#include <stdio.h> int main() { int a,b; scanf("%d%d",&a,&b); int x=0,y=0,z=0; for (int i=1; i<=a; i++) { for (int j=i+1; j<=a; j++) { if (((i&j) > x) && ((i&j) < b)) { x = i&j;

Sum of Digits of a Five Digit Number

C
4 years ago
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int n; scanf("%d", &n); int rem,sum=0;

Sum and Difference of Two Numbers

C
4 years ago
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int a,b,c,d; float x,y,z,w; scanf("%d%d",&a,&b);

subsets of a list

Python
4 years ago
l=[int(i) for i in input().split()] lists = [[]] for i in range(len(l) + 1): for j in range(i): lists.append(l[j: i]) print(lists) n=len(lists) new=[] for i in range(n): new.append(sum(lists[i]))

assigning array elements to the set

C++
4 years ago
#output will be 1 2 3 4 5 #for input n=8 #array elements 1 2 3 3 2 4 4 5 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++){

taking input from user and printing a set

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ set<int> s; int input; while(cin>>input){ s.insert(input); } for(auto it=s.begin();it!=s.end();++it){ cout<<*it<<" ";

initialising a set

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ set<int> s; s.insert(1); s.insert(6); s.insert(3); s.insert(2); s.insert(3); s.insert(1);

assigning stack elements to the vector and printing the elements

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ stack<int> s; int input; while(cin>>input){ s.push(input); } vector<int> v; while(s.empty()==0){

assigning values to stack from user at runtime

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ stack<int> s; int input; while(cin>>input){ s.push(input); } cout<<s.top()<<"\n"; return 0;

intialising a stack

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ stack<int> s; s.push(1); s.push(2); s.push(3); s.push(4); s.push(5); cout<<s.top()<<"\n";

removing duplicates from string using "OrderedDict"

Python
4 years ago
from collections import OrderedDict s=input() ans="".join(OrderedDict.fromkeys(s)) print(ans)

removing duplicates from string without order using set

Python
4 years ago
s=input() ans="".join(set(s)) print(ans)

printing each digit of a given number

Python
4 years ago
n=int(input()) s=str(n) for i in s: print(i)

sorting list in ascending order

Python
4 years ago
n=int(input()) l=[] l=[int(i) for i in input().split()] l.sort() for i in l: print(i,end=" ")

sort list elements in descending order

Python
4 years ago
n=int(input()) l=[] l=[int(i) for i in input().split()] l.sort(reverse=True) for i in l: print(i,end=" ")

pyramid pattern

Python
4 years ago
n=int(input()) k=0 for i in range(1,n+1): for j in range(1,(n-i)+1): print(end=" ") while(k != 2*i-1): print("*",end="") k+=1 k=0 print()

check whether given number is a power of given base

Python
4 years ago
def checkpowerofbase(n,b): if(n==0): return False; while(n != 1): if(n%b != 0): return False n=n//b return True num=int(input())