A program that I wrote using C as my programming language that will ask the user to give a number and then our program will generate the ordinal numerical values in a given number by our user. In this sample program I am using Turbo C 2.0 For DOS that is widely available free to download over the Internet.
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Program Listing
/* ordinal.c */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* Tools : Turbo C 2.0 For DOS */
/* Date : November 24, 2015 */
#include <stdio.h>
#include <conio.h>
int test(int i) {
char *message;
int a=0, mod100 = 0, mod10 = 0;
printf("\n");
for (a=1; a<=i; a++) {
mod100 = a % 100;
mod10 = a % 10;
if (mod10 == 1 && mod100 != 11) {
message= "st";
} else if (mod10 == 2 && mod100 != 12) {
message="nd";
}
else if (mod10 == 3 && mod100 != 13) {
message= "rd";
} else {
message= "th";
}
cprintf(" %d%s " ,a,message);
delay(2000);
}
}
main(){
int number=0;
clrscr();
textcolor(WHITE);
printf("\n");
cprintf("Ordinal Number Generator in C");
printf("\n\n");
cprintf("Enter a number : ");
scanf("%d",&number);
test(number);
printf("\n\n");
cprintf(" End of Program");
getche();
}
No comments:
Post a Comment