-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhelloworld.c
80 lines (69 loc) · 1.28 KB
/
helloworld.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
77
78
79
80
#include<stdio.h>
void slice(char *,int ,int);
int fact(int);
int main() {
int a=1,b=2,c;
int start,end;
char string[100],slicestr[100];
printf("Hello World!\n");
printf("The sum is %d\n",add(1,2));
swap(&a, &b);
printf("The diff is %d\n",sub(2,1));
printf("The multiplication is %d\n",multi(2,1));
printf("the division is %d\n", divide(a, b));
printf("Enter the string \n");
scanf("%s",string);
printf("Enter the start and end number :\n");
scanf("%d %d",&start,&end);
slice(string,start,end);
printf("The original string is %s\n",string);
printf("Enter a number to calculate it's factorial\n ");
scanf("%d",&c);
printf("The Factorial of %d =%d\n",c,fact(c));
return 0;
}
int add(int a,int b)
{
return (a+b);
}
int swap(int *a, int *b) {
*a = *a + *b;
*b = *a -*b;
*a = *a - *b;
}
int sub(int a ,int b)
{
return (a-b);
}
int multi(int a ,int b)
{
return(a*b);
}
// a/b
int divide(int a, int b) {
if (b != 0) {
return a/b;
} else {
printf("unable to divide!");
}
}
void slice(char* string ,int start,int end)
{ int k=0,i;
char slicestr[100];
for(i=start;i<end&&string[i]!='\0';i++)
{
slicestr[k]=string[i];
k++;
}
slicestr[k]='\0';
printf("The sliced string is %s\n",slicestr);
}
int fact(int c)
{
int i,k=1;
for(i=1;i<=c;i++)
{
k=k*i;
}
return k;
}