- 4
Write a program in c that replaces all 1's with 0's
You can write big or small programs
6 Respuestas
+ 2
// In that program replace all 0's with 1's
#include<stdio.h>
// A recursive function to replace all 0s with 1s in an input number
// It doesn't work if input number itself is 0.
int convert0To1Rec(int num)
{
// Base case for recursion termination
if (num == 0)
return 0;
// Extraxt the last digit and change it if needed
int digit = num % 10;
if (digit == 0)
digit = 1;
// Convert remaining digits and append the last digit
return convert0To1Rec(num/10) * 10 + digit;
}
// It handles 0 and calls convert0To1Rec() for other numbers
int convert0To1(int num)
{
if (num == 0)
return 1;
else return convert0To1Rec(num);
}
// Driver program to test above function
int main()
{
int num = 101020060;
printf("%d", convert0To1(num));
return 0;
}
+ 4
Kamlesh Kumar, have you understood what I just said?
The purpose of this app is not that school or college kids can log in and get their school homework done for them.
+ 4
Kamlesh Kumar going through the process of figuring out how to solve the problem is a good thing, then the user will be able to develop lots of muscle
+ 4
Kamlesh Kumar Yup you are right, we need to answer questions.
But in this case it seems most likely that OP is either
1. asking from Homework, Test or
2. challenging the community
In case 1, we ask OP to try to come up with their solution first and share the attempted code link with the question and only after seeing their attempt we help them.
In case 2, we request OP to not use Q&A to challenge the community, but either use the timed challenges or create a personal post with their challenge clearly described.
There's also opportunity to post Coding challenges which if gets accepted then shows up in the courses tab( leftmost tab)
+ 2
Kamlesh Kumar, please make teachers all over the world happy and don't do the homework for people. 😉
Always let them show their own attempt first.
+ 2
If anyone ask the question you should answer that question if you know, otherwise leave it.