Current streak:
0 days
Longest streak:
7 days
Less
More
void removeConsecutiveDuplicates(char *input)
{
if (input[0] == '\0')
{
return;
}
if (input[0] == input[1])
{
int i = 0;
while (input[i] != '\0')
{
input[i] = input[i + 1];
i++;
}
removeConsecutiveDuplicates(input);
}
else
{
removeConsecutiveDuplicates(input + 1);
}
}
#include <bits/stdc++.h>
int sumofDigits(int n)
{
int sum = 0;
// Calculate the sum of digits
while (n > 0)
{
sum += n % 10;
n /= 10;
}
// If the sum is still greater than or equal to 10, recursively call the function
if (sum >= 10)
{
return sumofDigits(sum);
}
return sum;
}
#include<iostream>
using namespace std;
int main()
{
int N;
cin>>N;
bool check=true;
for(int i=2;i<N;i++)
{
if(N%i==0)
{
check = 0;
}
}
if(check==1)
{
cout<<"true";
}
else
{
cout<<"false";
}
}
int firstIndexHelper(int input[], int size, int x, int currentIndex)
{
// Base case: If currentIndex reaches the end of the array, return -1
if (currentIndex == size)
{
return -1;
}
// If the current element is equal to x, return the current index
if (input[currentIndex] == x)
{
return currentIndex;
}
// Recursive case: Check the next element in the array
return firstIndexHelper(input, size, x, currentIndex + 1);
}
int firstIndex(int input[], int size, int x)
{
// Call the helper function with the initial currentIndex as 0
return firstIndexHelper(input, size, x, 0);
}
void symmetry(int n)
{
int spaces=0;
for(int i=0;i<n;i++)
{
//stars
for(int j=1;j<=n-i;j++)
{
cout<<"*"<<" ";
}
//spaces
for(int j=0;j<spaces;j++)
{
cout<<" "<<" ";
}
//stars
for(int j=1;j<=n-i;j++)
{
cout<<"*"<<" ";
}
spaces=spaces+2;
cout<<endl;
}
int i;
spaces=2*n-2;
for(int i=1;i<=n;i++)
{
//stars
for(int j=1;j<=i;j++)
{
cout<<"*"<<" ";
}
//spaces
for(int j=0;j<spaces;j++)
{
cout<<" "<<" ";
}
//stars
for (int j = 1; j <= i; j++) {
cout << "*"<< " ";
}
spaces = spaces - 2;
cout << endl;
}
}