Advertisement
Md_hosen_zisad

2s compliment

Oct 16th, 2017
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. { int i,l,j;
  5. char str[20];
  6. gets(str);
  7. l=strlen(str);
  8. for(i=l-1;i>=0;i--)
  9. {
  10. if(str[i]=='1')
  11. {
  12. break;
  13. }}
  14. for(j=i-1;j>=0;j--)
  15. {
  16. if(str[j]=='1')
  17. str[j]='0';
  18. else
  19. str[j]='1';
  20. }
  21. printf("%s",str);
  22.  
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement