Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 100
- char menu(void);
- void printNums(void);
- int isPrime(int num);
- void printPrime(void);
- int isEven(int num);
- void printEven(void);
- int isOdd(int num);
- void printOdd(void);
- int main(void)
- {
- char ch;
- char loop = 'y';
- printf("First Hundred Numbers are given below:\n");
- printNums();
- while(loop == 'y' || loop == 'Y'){
- fflush(stdin);
- ch = menu();
- if(ch == 'p' || ch == 'P')
- printPrime();
- else if(ch == 'e' || ch == 'E')
- printEven();
- else if(ch == 'o' || ch == 'O')
- printOdd();
- else
- printf("\nWRONG CHOICE!\n");
- printf("\n\nContinue? (y or n): ");
- scanf(" %c", &loop);
- system("cls");
- }
- printf("\n\n");
- return 0;
- }
- void printNums(void)
- {
- int nums[SIZE];
- int i;
- for(i=0; i<SIZE; i++){
- if((i%10) == 0){
- printf("\n");
- }
- nums[i] = i+1;
- printf("%5d", nums[i]);
- }
- }
- char menu(void)
- {
- char ch;
- printf("\n\n\n\t\tOPTIONS\n");
- printf("\t\t________\n\n");
- printf("1) To display prime numbers press 'P'.");
- printf("\n2) To display even numbers press 'E'.");
- printf("\n3) To display odd numbers press 'O'.\n");
- scanf("%c", &ch);
- return ch;
- }
- int isEven(int num)
- {
- if((num % 2) == 0)
- return 1;
- else
- return 0;
- }
- int isOdd(int num)
- {
- if((num % 2) != 0)
- return 1;
- else
- return 0;
- }
- int isPrime(int num)
- {
- int count=0;
- int i;
- for(i=1; i<=num; i++){
- if((num % i) == 0)
- count++;
- }
- if(count == 2)
- return 1;
- else
- return 0;
- }
- void printPrime(void)
- {
- int i;
- int nums[SIZE];
- char ch = '*';
- printf("\n\n\t\tPrime numbers are given below: \n\n");
- for(i=0; i<SIZE; i++){
- if((i%10) == 0){
- printf("\n");
- }
- nums[i] = i+1;
- if(isPrime(nums[i]))
- printf("%5d", nums[i]);
- else
- printf("%5c", ch );
- }
- }
- void printEven(void)
- {
- int i;
- int nums[SIZE];
- char ch = '*';
- printf("\n\n\t\tEven numbers are given below: \n\n");
- for(i=0; i<SIZE; i++){
- if((i%10) == 0){
- printf("\n");
- }
- nums[i] = i+1;
- if(isEven(nums[i]))
- printf("%5d", nums[i]);
- else
- printf("%5c", ch );
- }
- }
- void printOdd(void)
- {
- int i;
- int nums[SIZE];
- char ch = '*';
- printf("\n\n\t\tEven numbers are given below: \n\n");
- for(i=0; i<SIZE; i++){
- if((i%10) == 0){
- printf("\n");
- }
- nums[i] = i+1;
- if(isOdd(nums[i]))
- printf("%5d", nums[i]);
- else
- printf("%5c", ch );
- }
- }
Add Comment
Please, Sign In to add comment