-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday9.cpp
81 lines (74 loc) · 1.43 KB
/
day9.cpp
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
81
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
//array use dto store same type of data. which is contigious
int arr[5];
int size= sizeof(arr)/sizeof(arr[0]);
for (int i=0;i<size;i++)
{
cin>>arr[i];
}
//to print the output
for (int i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
cout<<"//find the sum of the given array:"<<endl;
int arr[6];
int sum=0;
cout<<"Enter manually number:"<<endl;
int size=sizeof(arr)/sizeof(arr[0]);
for (int i=0;i<size;i++)
{
//takeinput
cin>>arr[i];
}
cout<<endl;
//for output
for (int i=0;i<size;i++)
{
sum=sum+arr[i];
}
cout<<"The sum of the array is:"<<sum<<endl;
cout<<"//Question: calculate the maximum element from the array:"<<endl;
cout<<"Enter number manually by keypad:"<<endl;
int max[5];
int m=arr[0];
for (int i=0;i<5;i++)
{
cin>>max[i]; //take the input
}
for (int i=0;i<5;i++)
{
if (max[i]>m)
{
m=max[i];
}
}
cout<<"The maximum element in the array is:"<<m<<endl;
cout<<"Questoion: Search a given element in the array if it present return idx else -1:"<<endl;
//take input
int arrr[5];
int ans=-1;
cout<<"Enter the number manually by keypard:"<<endl;
for(int i=0;i<5;i++)
{
cin>>arrr[i];
}
//
int key;
cout<<"take input number that you want to search:"<<endl;
cin>>key;
//for itertae the loop to find key
for (int i=0;i<5;i++)
{
if (arrr[i]==key)
{
ans=i;
}
}
cout<<"Element at:"<<ans<<endl;
}