New in C! Help to solve this problem

Page 1 of 1

5 Replies - 176 Views - Last Post: 05 December 2017 - 09:54 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=408033&amp;s=f0c69e5d034051286300daafa6437381&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 laiaA

Reputation: 0
• Posts: 3
• Joined: 05-December 17

New in C! Help to solve this problem

Posted 05 December 2017 - 05:30 AM

I have to write a program that writes all the divisors of a positive integer n number introduced by the user.

That is what I have... do not know how to continue... Actually, it is not calculating all the divisors of the number. I am a computer science student in Barcelona !!

```#include <stdio.h>

int main()
{
int num, i, res;

printf("Introduce a positive number: ");
scanf ("%d", &num);

for (i%num == 0; i<=num; i++){

}
printf ("Divisors of %d are: %d", num, i);

}
```

This post has been edited by modi123_1: 05 December 2017 - 05:43 AM
Reason for edit:: In the future, please use the [code] tag button in the editor..

Is This A Good Question/Topic? 0

Replies To: New in C! Help to solve this problem

#2 modi123_1

• Suitor #2

Reputation: 13666
• Posts: 54,541
• Joined: 12-June 08

Re: New in C! Help to solve this problem

Posted 05 December 2017 - 05:44 AM

Why not put a print inside the for loop?

#3 laiaA

Reputation: 0
• Posts: 3
• Joined: 05-December 17

Re: New in C! Help to solve this problem

Posted 05 December 2017 - 09:46 AM

I already tried this option and compiles well but do not have any result.

#4 modi123_1

• Suitor #2

Reputation: 13666
• Posts: 54,541
• Joined: 12-June 08

Re: New in C! Help to solve this problem

Posted 05 December 2017 - 09:49 AM

Look at that for loop. What's up with any of that?
Where's the math involved?
Why is the loop control initialization "i%num == 0"?

Where's the math to do what you were looking to do?

#5 jimblumberg

Reputation: 5360
• Posts: 16,734
• Joined: 25-December 09

Re: New in C! Help to solve this problem

Posted 05 December 2017 - 09:52 AM

Quote

Why is the loop control initialization "i%num == 0"?

Excellent question, and laiaA realize that the initialization only happens once.

Jim

#6 laiaA

Reputation: 0
• Posts: 3
• Joined: 05-December 17

Re: New in C! Help to solve this problem

Posted 05 December 2017 - 09:54 AM

Got it !!

Thank you so much!!