Skip to content

Commit e64a64b

Browse files
Updated input file
1 parent 35bc3e2 commit e64a64b

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

prog1.c

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
1-
int max(int x, int y)
2-
{
3-
if(x > y)
4-
return y;
1+
#include<stdio.h>
52

6-
return x;
3+
int search(int arr[], unsigned int arr_len, int x){
4+
for (unsigned int i = 0; i < arr_len; i++)
5+
if (arr[(unsigned int)i] == x)
6+
return (int)i;
7+
return -1;
8+
}
9+
10+
int factorial(int num);
11+
12+
int verifyFactorial(int num){
13+
int fact = 1;
14+
if(num < 0){
15+
fact = -1;
16+
}
17+
else if(num > 1){
18+
do{
19+
fact = fact * num;
20+
num = num - 1;
21+
}while(num>1);
22+
}
23+
else {
24+
fact = 1;
25+
}
26+
return fact;
727
}
828

9-
/*
10-
You can write C code here or look at the examples.
11-
It will be translated as "demo/demo_translation.c".
12-
There are also translations of full programs below.
13-
*/
14-
void main(int argc, char** argv)
15-
{
16-
int i = 2, j = 2, k =2;
17-
if(2 >1)
18-
{printf("true");}
19-
else {printf("false");}
20-
while (j>i)
21-
{j=j-1;
22-
i=i+1;}
23-
printf("Value of this %d And done.\n", i+j+k);
24-
printf("Value of argument %d And done.\n", argc);
25-
printf("Value of this %d And done.\n", i+j+k);
29+
void main() {
30+
int arr[] = { 1, 2, 3, 4, 5, 6 };
31+
int num = 6;
32+
int result = search(arr, 6, num);
33+
printf("%d\n", result);
34+
result = factorial(num);
35+
printf("%d\n", result);
36+
}
2637

38+
//This should be linked to its function declaration
39+
int factorial(int num){
40+
int copyNum = num;
41+
int fact = 1;
42+
if(num < 0)
43+
fact = -1;
44+
else{
45+
while(num > 1){
46+
fact = fact * num--;
47+
}
48+
}
49+
return fact==verifyFactorial(copyNum)? fact:-2;
2750
}
51+
52+

0 commit comments

Comments
 (0)