Need help with C language introductory first year course tha
Need help with C language... introductory first year course, thank you!
Solution
#include <stdio.h>
 char romanval[1000];
 int i;
 //Find out the predigits
 void predigit(char num1, char num2)
 {
 romanval[i++] = num1;
 romanval[i++] = num2;
 }
 //Find out the post digit
 void postdigit(char c, int n)
 {
 int j;
 for (j = 0; j < n; j++)
 romanval[i++] = c;
 }
int main()
 {
 int j;
 long number;
 //Loops until -1 is entered as number
 do
 {
 i = 0;
 printf(\"\ Enter the number: \");
 //Accepts a number
 scanf(\"%d\", &number);
 //Loops until the entered number is not zero
 while (number != 0)
 {
 //Checks if the number is greater than equal to 1000
 if (number >= 1000)
 {
 //Roman letter is M for 1000
 postdigit(\'M\', number / 1000);
 number = number - (number / 1000) * 1000;
 }
 //Checks if the number is greater than equal to 500
 else if (number >= 500)
 {
 if (number < (500 + 4 * 100))
 {
 //Roman letter is D for 500
 postdigit(\'D\', number / 500);
 number = number - (number / 500) * 500;
 }
 else
 {
 predigit(\'C\',\'M\');
 number = number - (1000-100);
 }
 }
 //Checks if the number is greater than equal to 100
 else if (number >= 100)
 {
 if (number < (100 + 3 * 100))
 {
 //Roman letter is C for 100
 postdigit(\'C\', number / 100);
 number = number - (number / 100) * 100;
 }
 else
 {
 predigit(\'L\', \'D\');
 number = number - (500 - 100);
 }
 }
 //Checks if the number is greater than equal to 50
 else if (number >= 50 )
 {
 if (number < (50 + 4 * 10))
 {
 //Roman letter is L for 50
 postdigit(\'L\', number / 50);
 number = number - (number / 50) * 50;
 }
 else
 {
 predigit(\'X\',\'C\');
 number = number - (100-10);
 }
 }
 //Checks if the number is greater than equal to 10
 else if (number >= 10)
 {
 if (number < (10 + 3 * 10))
 {
 //Roman letter is X for 10
 postdigit(\'X\', number / 10);
 number = number - (number / 10) * 10;
 }
 else
 {
 predigit(\'X\',\'L\');
 number = number - (50 - 10);
 }
 }
 //Checks if the number is greater than equal to 5
 else if (number >= 5)
 {
 if (number < (5 + 4 * 1))
 {
 //Roman letter is V for 5
 postdigit(\'V\', number / 5);
 number = number - (number / 5) * 5;
 }
 else
 {
 predigit(\'I\', \'X\');
 number = number - (10 - 1);
 }
 }
 //Checks if the number is greater than equal to 1
 else if (number >= 1)
 {
 if (number < 4)
 {
 //Roman letter is I for 1
 postdigit(\'I\', number / 1);
 number = number - (number / 1) * 1;
 }
 else
 {
 predigit(\'I\', \'V\');
 number = number - (5 - 1);
 }
 }
 }
 //Displays the roman letter format for inputted number
 printf(\"Roman number is: \");
 for(j = 0; j < i; j++)
 printf(\"%c\", romanval[j]);
}while(number != -1);
 return 0;
 }
Output:
Enter the number: 33
 Roman number is: XXXIII
 Enter the number: 61
 Roman number is: LXI
 Enter the number: 123
 Roman number is: CXXIII
 Enter the number: 789
 Roman number is: DCCLXXXIX
 Enter the number: 652
 Roman number is: DCLII
 Enter the number: 1234
 Roman number is: MCCXXXIV
 Enter the number: 658
 Roman number is: DCLVIII
 Enter the number: -1
![Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi](/WebImages/31/need-help-with-c-language-introductory-first-year-course-tha-1087054-1761571761-0.webp)
![Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi](/WebImages/31/need-help-with-c-language-introductory-first-year-course-tha-1087054-1761571761-1.webp)
![Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi Need help with C language... introductory first year course, thank you!Solution#include <stdio.h> char romanval[1000]; int i; //Find out the predigits voi](/WebImages/31/need-help-with-c-language-introductory-first-year-course-tha-1087054-1761571761-2.webp)
