5 Replies - 210 Views - Last Post: 05 December 2017 - 09:54 AM Rate Topic: -----

#1 laiaA   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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);   
    
}
:code:

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   User is online

  • Suitor #2
  • member icon



Reputation: 14174
  • View blog
  • Posts: 56,774
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 laiaA   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14174
  • View blog
  • Posts: 56,774
  • 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?
Was This Post Helpful? 1
  • +
  • -

#5 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,111
  • 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
Was This Post Helpful? 0
  • +
  • -

#6 laiaA   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1