S

@Shobh89

Program to find whether a given number is power of 2

C++
1 year ago
//C program for above approach #include <iostream> using namespace std; /* Function to check if x is power of 2*/ bool isPowerOfTwo(int n) { /* First x in the below expression is for the case when *x is 0 */

q-2

C++
1 year ago
#include <iostream> using namespace std; int main() { cout << (10 << 2) << endl; cout << (10 >> 1) << endl; return 0; }

q-1

C++
1 year ago
#include <iostream> using namespace std; int main() { int a=6,b=10; int c=6,d=10; int e=6,f=10; cout << (a & b) << endl; cout << (c | d) << endl; cout << (e ^ f) << endl;

C Program for Program for array rotation

C
1 year ago
//C program to illustrate how to rotate array #include <stdio.h> //Function to rotate array left by one position void leftRotatebyOne(int arr[], int n) { int temp=arr[0]; for(int i=0;i<n-1;i++){ arr[i]=arr[i+1]; }

binary to decimal

C++
1 year ago
#include <iostream> using namespace std; int binToDecimal(int binNum){ int ans=0,pow=1; while(binNum>0){ int rem=binNum % 10; ans+= rem*pow;

C Program to Find Common Array Elements Between Two Arrays

C
1 year ago
//C program to demonstrate scrunity of // 2 Common Array elements Using Brute force #include <stdio.h> int main() { int array1[]={8,2,3,4,5,6,7,1}; int array2[]={4,5,7,11,6,1}; int i,j,flag,x,k=0; int result[100];

C Program to Copy All the Elements of One Array to Another Array

C
1 year ago
//C program to copy all the elements //of one array to another #include <stdio.h> int main() { int a[5]={3,6,9,2,5},n=5; int b[n],i;

C Program to Remove All Occurrences of an Element in an Array

C
1 year ago
//C program to remove All Occurences of //an element in an array using function #include <stdio.h> //Function declaration int remove_element(int* array,int n,int val) { int i; //iterates array elements

C Program To Merge Two Arrays

C
1 year ago
//C program to merge two arrays into a new array using //memcpy() #include <stdio.h> #include<string.h> #include<stdlib.h> int* mergeArrays(int arr1[],int n1,int arr2[],int n2){ //Resultant array to store merged array int *res = (int*)malloc(sizeof(int) * n1 * n2);

Code for decimal to binary

C++
1 year ago
#include <iostream> using namespace std; int decTobinary(int decNum){ int ans=0,pow=1; while(decNum>0){ int rem = decNum % 2; decNum/=2;

C Program To Remove Duplicates From Sorted Array

C
1 year ago
//C Program to remove duplicates from a sorted array //using two-pointer technique #include <stdio.h> int removeDuplicates(int arr[],int N){ //If array is empty,return 0 if(N == 0) { return 0; }

Nth Fibonacci Number

C++
1 year ago
// Fibonacci Series using Space Optimized method #include <iostream> using namespace std; int fib(int n) { int a=0,b=1,c,i; if(n==0) return a; for(i=2;i<=n;i++){

WAF to print all prime numbers from 1 to N

C++
1 year ago
// C++ program to display Prime numbers till N #include <iostream> using namespace std; //function to check if a given number is prime bool isPrime(int n) { //since 0 and 1 is not prime return false if(n == 1 || n==0) return false;

WAF to check a number is prime or not

C++
1 year ago
#include <iostream> using namespace std; bool check_prime(int); int main() { int n; cout<<"Enter a positive integer: ";

Calculate nCr binomial coefficient for n and r

C++
1 year ago
#include <iostream> using namespace std; int factoial(int n){ int fact=1; for(int i=1;i<=n;i++){ fact *=i; } return fact;

Calculate sum of digits of a number

C++
1 year ago
#include <iostream> using namespace std; int sumOfDigits(int num){ int digSum=0; while(num>0){ int lastDig= num % 10; num /=10;

Calculate N factorial

C++
1 year ago
#include <iostream> using namespace std; int factorialN(int n){ int fact=1; for(int i=1;i<=n;i++){ fact*=i; } return fact;

sum of numbers from 1 to n(c++) functions

C++
1 year ago
#include <iostream> using namespace std; int sumN(int n){ int sum=0; for(int i=1;i<=n;i++){ sum+=i; } return sum;

2d array in C

C
1 year ago
#include <stdio.h> const int M =3; const int N =3; void print(int arr[M][N]) { int i,j; for(i=0;i<M;i++) for(j=0;j<N;j++) printf("%d ",arr[i][j]);

Program to Print Butterfly Pattern (Star Pattern)

C++
1 year ago
#include <iostream> using namespace std; int main() { //Number of Rows int N=5; //Variables to store number of spaces and stars int spaces=2*N-1;