-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddOf2numArrayList.c
61 lines (51 loc) · 1.83 KB
/
addOf2numArrayList.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
/**
* @file addOf2numArrayList.c
* There’s a list of number in a row on the table. Your teacher is telling a number which is the addition of any of the two number from the given number list on the table.
* Your job is to find that two number which addition is equal to the number given by your teacher. If there’s no pair of number in a list is equal to the given number by your teacher,
* then you will say “Sir, there’s no pair of numbers equal to your number” otherwise you will show that two number which addition is equal to the given number by your teacher.
* Write a program to solve the situation.
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-03-16
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
void main()
{
int i, next, temp, s, n, f=0;
printf("Enter the list size: \n");
scanf("%d", &n);
int lis[n];
printf("Enter the list value: \n");
for (i = 1; i <= n; i++)
{
scanf("%d", &lis[i]);
}
printf("teacher is telling, the number is: ");
scanf("%d", &s);
temp = s;
for (i = 1; i <= n; i++)
{
for (next = i + 1; next <= n; next++)
{
if (temp == lis[i] + lis[next])
{
f++;
printf("%d is addition of this %d and %d numbers.\n", s, lis[i], lis[next]);
break;
}
}
// if we get our result, so don't need to continue the outer loop also.
if (f == 1)
{
break;
}
}
if (f== 0)
{
printf("Sir, there\'s no pair of numbers equal to your %d number\n", s);
}
}