#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Output on Same Line


    Hello again. I was wondering if there was any way to print the output values all onto one line. For example, this is something I'm currently working on. Given an integer n the program must output its equivalent in roman numerals.

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
        int n,a;
        scanf("%d", &n);   
        a=n/5;
        if(a==1)
        {
                if(n==9)
                {
                        printf("IX\n");
                        n=n-9;
                }
                else
                {
                        printf("V\n");
                        n=n-5;
                }
        }
        switch(n)
        {
                 case 1:
                      printf("I\n");
                      break;
                 case 2:
                      printf("II\n");
                      break;
                 case 3:
                      printf("III\n");
                      break;
                 case 4:
                      printf("IV\n");
                      break;
        }
        getch();
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    Yeah, don't include the newline '\n' until your done printing on that line. In your example.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int n,a;
        scanf("%d", &n);   
        a=n/5;
        if(a==1)
        {
                if(n==9)
                {
                        printf("IX");
                        n=n-9;
                }
                else
                {
                        printf("V");
                        n=n-5;
                }
        }
        switch(n)
        {
                 case 1:
                      printf("I");
                      break;
                 case 2:
                      printf("II");
                      break;
                 case 3:
                      printf("III");
                      break;
                 case 4:
                      printf("IV");
                      break;
        }
        fputs("\n", stdout);
        return 0;
    }

IMN logo majestic logo threadwatch logo seochat tools logo