d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso: C Programming Help
Add Reply New Topic New Poll
Member
Posts: 36,366
Joined: Mar 13 2007
Gold: 18,943.50
Trader: Trusted
Feb 12 2013 10:22am
FT: Fg.

It's some basic C (NOT C++).

Lmk if anyone can help out.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 11:36am
post











code?



and questions?
Member
Posts: 36,366
Joined: Mar 13 2007
Gold: 18,943.50
Trader: Trusted
Feb 12 2013 11:41am
Quote (AbDuCt @ Feb 12 2013 01:36pm)
post











code?



and questions?


PM'd.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 11:46am
Code
[QUOTE=Floozy,Feb 12 2013 01:41pm]

#include <stdio.h>

int main () {
   int T, N, curCase;
   int b;


   scanf("%d", &T);

   for (curCase = 1; curCase <= T; curCase++) {
       scanf("%d", &N);

       printf("Case %d: %d\n", curCase, N);

   for (b = 2; b <= T; b++) {
       if (N%b == 0)
           printf("(%d,%d)", b, N/b);

       }

   for (b = 5; b <= T; b++) {
       if (N%b == 0)
           printf("(%d,%d)", b, N/b);
           if (N%b > 0);
               printf("%d is a prime!");

       }

       printf("\n");

   }

   return 0;
}


I have to get it to print a line after each case, which it's not already doing.

Also, I need it to print the pairs of factors for each number without repeating any pairs. (i.e. - 2,5 and 5,2 for 10)

The first number of the pairs also has to be in ascending order too.

Like:

12:
(2,6)
(3,4)


This is how the sample I/O should look:

Input:

4
9
10
11
12

Output:

Case 1: 9
(3,3)

Case 2: 10
(2,5)

Case 3: 11
This number is a prime!

Case 4: 12
(2,6)
(3,4)





Mine atm looks like:
4
9
10
11
12

Output:
Case 1: 9
(3,3)
Case 2: 10
(2,5)
Case 3: 11

Case 4: 12
(2,6)(3,4)(4,3)
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 11:47am
answer use the \n flag to add a newline after each statement. (to be used with stdout funcitions such as printf, sprintf, and the like)
Member
Posts: 36,366
Joined: Mar 13 2007
Gold: 18,943.50
Trader: Trusted
Feb 12 2013 11:49am
Quote (AbDuCt @ Feb 12 2013 01:47pm)
answer use the \n flag to add a newline after each statement. (to be used with stdout funcitions such as printf, sprintf, and the like)


I know that already. ~_~
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 11:51am
Quote (Floozy @ Feb 12 2013 01:49pm)
I know that already. ~_~



I have to get it to print a line after each case, which it's not already doing.

Case 4: 12
(2,6)(3,4)(4,3)

Code
for (b = 2; b <= T; b++) {
      if (N%b == 0)
          printf("(%d,%d)", b, N/b);

      }


Case 4: 12
(2,6)
(3,4)


apparently you dont

if that is not what you meant please clarify

This post was edited by AbDuCt on Feb 12 2013 11:51am
Member
Posts: 36,366
Joined: Mar 13 2007
Gold: 18,943.50
Trader: Trusted
Feb 12 2013 12:54pm
Quote (AbDuCt @ Feb 12 2013 01:51pm)
I have to get it to print a line after each case, which it's not already doing.

Case 4: 12
(2,6)(3,4)(4,3)

Code
for (b = 2; b <= T; b++) {
      if (N%b == 0)
          printf("(%d,%d)", b, N/b);

      }


Case 4: 12
(2,6)
(3,4)


apparently you dont

if that is not what you meant please clarify


Quote (AbDuCt @ Feb 12 2013 01:51pm)
I have to get it to print a line after each case, which it's not already doing.

Case 4: 12
(2,6)(3,4)(4,3)

Code
for (b = 2; b <= T; b++) {
      if (N%b == 0)
          printf("(%d,%d)", b, N/b);

      }


Case 4: 12
(2,6)
(3,4)


apparently you dont

if that is not what you meant please clarify


Already figured that out. I now need to know how to print when the number is prime and to eliminate doubles.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll