Divisors

Read an integer variable and print all of its divisors (including 1 and the number itself).

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#include <stdio.h>

int main() {
int A,i,X;
scanf(“%d”,&A);
for(i=1;i=A;i++){
X=A%i;
if(X==0){
printf(“%d\n”,&i);
}
}

return 0;

}

how can I make this efficient??

#include<stdio.h>
int main() {
int A,i,X;
scanf(“%d”,&A);
for(i=1;i<=A;i++){
X=A%i;
if(X==0)
printf(“%d\n”,i);
}
return 0;
}

for loop condition should be i<=A,i=A means i assigned by the value of A,for loop conditional expression should be an operator.
printf variable shouldn’t be addressed using &, in that statement it prints the memory address of i.

anyway thanks for the unnecessary suggestionsuggestion

Well I’m a beginner level and haven’t much experienced yet.So I thincked that way.

#include <stdio.h>

int main() {
int n,i;
scanf(“%d”,&n);
for(i=1;i<=n;i++){
if(n % i == 0){
printf(“%d”,i);
}
}
return 0;
}

Whats the problem in this code?

you try another digites like 5 or 4 , 7 and then you will see your code not working properly

#include<stdio.h>
int main(){
int n;
scanf(“%d”,&n);
for(int i=n;i<=n;i–){
int a=n/i;
if(n%i==0){
printf(“%d\n”,a);
}
}
return 0;
}

what is wrong with this code??

it shows runtime error

#include <stdio.h>
int main() {
int i, A;
printf(“Enter the value of n: “);
scanf(”%d”, &A);

if(A < 100){
for(i = 1; i <= A; i++){
if(A % i == 0){
printf(“%d \n”, i);
}
}
}

return 0;
}

it solution why don’t accept

@hjr265 d8 submission failing cause input does not ends with a newline.

1 Like

Test cases have been updated. Your submission has been rejudged. Thanks for reporting!