View difference between Paste ID: pU8cLv0J and dLxuRDU3
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <stdlib.h>
3
4
#define SIZE 100
5
6
char menu(void);
7
void printNums(void);
8
int isPrime(int num);
9
void printPrime(void);
10
int isEven(int num);
11
void printEven(void);
12
int isOdd(int num);
13
void printOdd(void);
14
15
int main(void)
16
{
17
	char ch;
18
	char loop = 'y';
19
20
	printf("First Hundred Numbers are given below:\n");
21
	printNums();
22
	
23
24
	while(loop == 'y' || loop == 'Y'){
25
26
		fflush(stdin); 
27
		ch = menu();
28
		
29
		if(ch == 'p' || ch == 'P')
30
			printPrime();
31
		else if(ch == 'e' || ch == 'E')
32
			printEven();
33
		else if(ch == 'o' || ch == 'O')
34
			printOdd();
35
		else
36
			printf("\nWRONG CHOICE!\n");
37
38
39
40
		printf("\n\nContinue? (y or n): ");
41
		scanf(" %c", &loop);
42
43
		system("cls");
44
45
	}
46
47
	printf("\n\n");
48
49
	return 0;
50
}
51
52
53
void printNums(void)
54
{
55
	int nums[SIZE];
56
	int i;
57
58
	for(i=0; i<SIZE; i++){
59
		if((i%10) == 0){   
60
			printf("\n");
61
		}
62
		nums[i] = i+1;
63
		printf("%5d", nums[i]);
64
	}
65
66
}
67
68
69
char menu(void)
70
{
71
	char ch;
72
73
	printf("\n\n\n\t\tOPTIONS\n");
74
	printf("\t\t________\n\n");
75
	printf("1) To display prime numbers press 'P'.");
76
	printf("\n2) To display even numbers press 'E'.");
77
	printf("\n3) To display odd numbers press 'O'.\n");
78
	scanf("%c", &ch);
79
80
	return ch;
81
82
}
83
84
int isEven(int num)
85
{
86
	if((num % 2) == 0)
87
		return 1;
88
	else
89
		return 0;
90
}
91
92
int isOdd(int num)
93
{
94
	if((num % 2) != 0)
95
		return 1;
96
	else 
97
		return 0;
98
}
99
100
int isPrime(int num)
101
{
102
	int count=0;
103
	int i;
104
105
	for(i=1; i<=num; i++){
106
		if((num % i) == 0)
107
			count++;
108
	}
109
110
	if(count == 2)
111
		return 1;
112
	else
113
		return 0;
114
	
115
}
116
117
void printPrime(void)
118
{
119
	int i;
120
	int nums[SIZE];
121
	char ch = '*';
122
	printf("\n\n\t\tPrime numbers are given below: \n\n");
123
	for(i=0; i<SIZE; i++){
124
		if((i%10) == 0){  
125
			printf("\n");
126
		}
127
		nums[i] = i+1;
128
		if(isPrime(nums[i]))
129
			printf("%5d", nums[i]);
130
		else
131
			printf("%5c", ch );
132
	}
133
}
134
135
void printEven(void)
136
{
137
	int i;
138
	int nums[SIZE];
139
	char ch = '*';
140
141
	printf("\n\n\t\tEven numbers are given below: \n\n");
142
143
	for(i=0; i<SIZE; i++){
144
		if((i%10) == 0){   
145
			printf("\n");
146
		}
147
		nums[i] = i+1;
148
		if(isEven(nums[i]))
149
			printf("%5d", nums[i]);
150
		else
151
			printf("%5c", ch );
152
	}
153
}
154
155
void printOdd(void)
156
{
157
	int i;
158
	int nums[SIZE];
159
	char ch = '*';
160
161
	printf("\n\n\t\tEven numbers are given below: \n\n");
162
163
	for(i=0; i<SIZE; i++){
164
		if((i%10) == 0){   
165
			printf("\n");
166
		}
167
		nums[i] = i+1;
168
		if(isOdd(nums[i]))
169
			printf("%5d", nums[i]);
170
		else
171
			printf("%5c", ch );
172
	}
173
}