THE QUESTION SAY: Programming: Create the following three files: 1)main.c: main
ID: 3756771 • Letter: T
Question
THE QUESTION SAY:
Programming: Create the following three files:
1)main.c: main function that calls printStrings(int length) in myfunctions.c
2)myfunctions.c: has two functions
• printStrings: initializes a string s and call printStringsRec
• printStringsRec: a recursive function that prints all possible binart strings of size ‘length’
such that printed strings have no consecutive 1’s.
• Example: if length=3 then output: 000, 001,010,100,101 but not 110 nor 011
3)myfunctions.h: a header file to hold the two functions prototypes.
//Main.c
int main() {
int length;
scanf(“Enter string length: %d”,&length);
printStrings(length) ;
return 0;
}
For submission please write the run command used and the printed output in
addition to the code.
(in c programming language)
==================
I did write the code
The code is :
/.h file declaration of two functions
void printStrings(int length);
void printStringsRec(char *S, int length);
-----------------------------------
//.c file for defintion of functions in .h file
void printStrings(int length)
{
char *s = (char*)malloc(length * sizeof(char));
/*printf("Enter numbers : ");
scanf_s("%s", s);*/
strcpy(s, "121131114");
printStringsRec(s, length);
}
void printStringsRec(char *s, int length)
{
int i = length-1;
if (length == 0)
return;
printf("String: ");
while (i >=0 )
{
if (s[i] == 49 )
{
if (s[i - 1] != 49)
printf("%c", s[i--]);
else
break;
}
else
printf("%c", s[i--]);
}
printf(" ");
printStringsRec(s, --length);
}
-------------------------------------------------
//main.cpp
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int length;
printf("Length: ");
scanf_s("%d", &length);
printStrings(length);
return 0;
}
but I have no idea how to make it binary
as the example in the QUESTION number 3
which say :
Example: if length=3 then output: 000, 001,010,100,101 but not 110 nor 011
please help me to fix my codes and Achievement required of the output they ask me for
please and thank you
Explanation / Answer
void rollover(int value,int countr) {
if(countr==0) {
return;
}
printf("%d ",value);
countr--;
rollover(value,countr);
}
int main() {
int arry[]={0,1};
for(int i=0;i<=1;i++) {
rollover(arry[i],4);
}
printf(" ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.