-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab 3 - Prime Numbers and String Manipulation.c
76 lines (62 loc) · 1.24 KB
/
Lab 3 - Prime Numbers and String Manipulation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
int prime(int end)
{
int i, x, y;
for(i=2; i<=end; i++)
{
y = 1;
for(x=2; x<=i/2; x++)
{
if(i%x==0)
{
y = 0;
break;
}
}
if(y==1)
{
printf("%d\n", i);
}
}
}
int string_length(char *pointer)
{
int c = 0;
while( *(pointer+c) != '\0' )
c++;
return c;
}
void reverse(char *string)
{
int length, c;
char *begin, *end, temp;
length = string_length(string);
begin = string;
end = string;
for ( c = 0 ; c < ( length - 1 ) ; c++ )
end++;
for ( c = 0 ; c < length/2 ; c++ )
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
int main()
{
int end;
printf("Q1 \n");
printf("Find prime numbers up to : ");
scanf("%d", &end);
printf("All prime numbers between 1 to %d are:\n", end);
prime(end);
char string[50];
printf("\nQ2\n");
printf("Enter a string: ");
scanf("%s", &*string);
reverse(string);
printf("Reverse of string is: %s", string);
return 0;
}