Search found 2 matches

by Nahian37
Tue Oct 23, 2012 6:37 pm
Forum: Volume 109 (10900-10999)
Topic: 10931 - Parity
Replies: 18
Views: 9684

Re: 10931 - Parity (why compile error)

#include<cstdio> #include<cstdlib> #include<cstring> int main() { long long int k,i,j,d,c,n; char a[1000000]; while(scanf("%lld",&n)==1&&n!=0) { c=0; j=0; while(n!=0) { d=n%2; a[j]=d+48; n=n/2; j++; } for(i=0;a !=NULL;i++) { if(a =='1') { c++; } } strrev(a); printf("The parity of %s is %lld (mod 2)....
by Nahian37
Sun Oct 14, 2012 11:50 am
Forum: Volume 111 (11100-11199)
Topic: 11185 - Ternary
Replies: 34
Views: 13494

Re: 11185 - Ternary

#include<stdio.h> int main() { long n,i,j,a[50]; while(1) { scanf("%ld",&n); if(n<=0) break; for(i=0;n>0;i++) { a =n%3; n=n/3; } for(j=i-1;j>=0;j--) { printf("%ld",a[j]); } printf("\n"); } return 0; } whats the problem with this code?

Go to advanced search