[Solved] Converting an iterative algorithm to a recursive one [closed]

This is almost the same as BLUEPIXY‘s answer since I believe it’s the straight forward solution, but since you are confused by the function pointer, I removed that. #include <stdio.h> #include <stdlib.h> void printValue() { static unsigned int y; printf(“%d\n”, y); y += 1; } void recursiveFunction(int counter) { printValue(); if (–counter == 0) return; … Read more

[Solved] Program to remove all the consecutive same letter from a given string [closed]

printf(“%s\n”,str2[k]); str2[k] is a char, but you tell printf it is a char* But this program still will not work properly – the first call to gets() will just read the carriage-return that is left in the input queue after reading the initial int value. And you never null-terminate str2. solved Program to remove all … Read more

[Solved] print all possible strings of length p that can be formed from the given set [closed]

A possible approach could be to start from an empty string and add characters one by one to it using a recursive function and printing it. Here is my code: #include<stdio.h> #include<stdlib.h> #include<string.h> void print_string(char str[],char new_str[],int current_len,int n,int len) { /* str=orignal set, new_str=empty char array, current_len=0(Intially) n=no of elements to be used len=the … Read more

[Solved] I can’t figure out this sequence – 11110000111000110010

There are many possible solutions to this problem. Here’s a reusable solution that simply decrements from 4 to 1 and adds the expected number of 1’s and 0’s. Loops used : 1 def sequence(n): string = “” for i in range(n): string+=’1’*(n-i) string+=’0’*(n-i) return string print sequence(4) There’s another single-line elegant and more pythonic way … Read more

[Solved] Fast algorithm needed [closed]

Just make simple algebraic transformations start * c^n = stop c^n = stop / start c = (stop / start)^(1/n) (math.pow or power function in some programming languages) solved Fast algorithm needed [closed]

[Solved] odds to the first and evens last

How about this solution #include<stdio.h> int main() { int i; int arr[]={ 2, 1 ,4 ,3 ,6 ,5 ,8 ,7 ,9}; int arr_size = sizeof(arr)/sizeof(arr[0]); int sorted[arr_size]; int sp = 0; for(i=0;i<arr_size;i++){ if(arr[i]&1){ sorted[sp++]=arr[i]; } } for(i=0;i<arr_size;i++){ if(!(arr[i]&1)){ sorted[sp++]=arr[i]; } } for(i=0;i< arr_size ;i++) printf(“%d “, sorted[i]); return 0; } the output is 1 3 … Read more