- 4

Write a program in c that replaces all 1's with 0's

You can write big or small programs

12th Sep 2019, 10:52 AM
Akhil Râj
Akhil Râj - avatar
6 Answers
+ 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; }
12th Sep 2019, 11:30 AM
Kamlesh Kumar
Kamlesh Kumar - avatar
+ 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.
12th Sep 2019, 1:48 PM
HonFu
HonFu - avatar
+ 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
12th Sep 2019, 1:54 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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)
12th Sep 2019, 2:06 PM
Morpheus
Morpheus - avatar
+ 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.
12th Sep 2019, 1:27 PM
HonFu
HonFu - avatar
+ 2
If anyone ask the question you should answer that question if you know, otherwise leave it.
12th Sep 2019, 1:30 PM
Kamlesh Kumar
Kamlesh Kumar - avatar