Header Ads

Header ADS

Solution of URI 1133::Rest of a Division

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>

int main() {

    long int n1,n2,i=0,j=0;

    scanf("%ld%ld",&n1,&n2);


    if(n2>n1) {
       for(i=n1+1;i<n2;i++) {
        if((i%5)==2 ||(i%5)==3) {
             printf("%ld\n",i);
            }
       }

    }

    else if (n1>n2) {
          for(i=n2+1;i<n1;i++) {
             if((i%5)==2 ||(i%5)==3) {
                 printf("%ld\n",i);
            }
    }

    }



    return 0;
}



                                                       OR



#include <stdio.h>

int main() {
    long int n1,n2,arr[10000],i=0,j=0;

    scanf("%ld%ld",&n1,&n2);


    if(n2>n1) {
    for(i=n1+1;i<n2;i++) {
        if((i%5)==2 ||(i%5)==3) {
            arr[j]= i;
            j++;
        }
    }

    }

    else if (n1>n2) {
          for(i=n2+1;i<n1;i++) {
        if((i%5)==2 ||(i%5)==3) {
            arr[j]= i;
            j++;
        }
    }

    }

    for(i=0;i<j;i++) {
    printf("%ld\n",arr[i]);
    }

    return 0;
}

No comments

Theme images by konradlew. Powered by Blogger.