Sunteți pe pagina 1din 10

# ASSIGNMENT # [1]

SEMESTER 3rd

## Lecturer in computer science

1
1) C++ program to store and calculate the sum of 4 numbers
entered by the user using arrays.
#include <iostream>
using namespace std;
int main()
{
int numbers[4], sum = 0;
cout << "Enter 4 numbers: ";
for (int i = 0; i < 4; ++i)
{
cin >> numbers[i];
sum = numbers[i];
}
cout << "Sum = " << sum << endl;
return 0;
}
output
Enter 4 numbers: 2

2
4
1
3
sum = 10

## 2) C++ program to store and calculate the subtraction of 5

numbers entered by the user using arrays.
#include <iostream>
using namespace std;
int main()
{
int numbers[5], sum = 0;
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i)
{
cin >> numbers[i];
sub = numbers[i];
}
cout << "subtraction = " << sub << endl;
return 0;
}
output
Enter 4 numbers: 9

3
2
4
1
sub = 2

## 3) Find out and print the maximum value in the array.

#include <iostream>

main()

int i ;

cin>>xyz[i];

4
max = xyz [i] ;

output

## Enter values in element i = 2 , 4, 5, 6, 7

maximum value = 7

## 4) Printing my name using array

#include <iostream.h>

int main()

## for (i=0; i<=6; i++){

cout<<str[i];

return 0;

Output

IZHAR

5
5) Access Array Elements Using Pointer
#include <iostream>

int main()

int data[4];

return 0;

output

## 6) Show Largest Element of an array

#include <iostream>

6
using namespace std;

int main()

int i, n;

float arr[100];

cin >> n;

arr[0] = arr[i];

return 0;

7
output

## Enter total number of elements: 4

Enter Number 1: 44

Enter Number 2: 55

Enter Number 3: 66

## Enter Number 4:77

Largest element = 77

## 7) Calculate Average of Numbers Using Array

#include <iostream>

int main()

int n, i;

cin >> n;

8
cin >> n;

## cin >> num[i];

sum += num[i];

average = sum / n;

return 0;

output

## Enter the numbers of data: 3

1. Enter number: 23

2. Enter number: 12

3. Enter number: 45

## 8) Findind position of values using array

#include <iostream>

#include<conio.h>

9
using namespace std;

int main()

int i;

## cout<<"Single Dimensional Array Example \n";

for (i=0;i<3;i++)

return 0;

output

## Single Dimensional Array Example

Position : 0 , Value : 5

Position : 1 , Value : 10

10