0% found this document useful (0 votes)
6 views10 pages

Exp 5 Fundamentals of C Programming by Urk21bt1053

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Exp 5 Fundamentals of C Programming by Urk21bt1053

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

20CS1003L – Fundamentals of programming for URK21C

Problem Solving Lab S

Ex. No. 5 Arrays


Date of NAME :VENKATESAN G
22/03/2022
Exercise REG NO :URK21BT1053

Aim:
.

Algorithm:

1. start the program


2. define an integer array array[100]
3. read the number of elements (n)
4. initialize c=0; sum=0
5. repeat steps 6 and 7 using for loop that ranges from 1 to n
6. read the elements of the array
7. sum = sum + array[c]
8. display the sum
9. stop the program

Description:
Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the
same type. An array is used to store a collection of data, but it is often more useful to think of an
array as a collection of variables of the same type.

Declaration of C Array
data_type array_name[array_size];
Example: int marks[5];

Initialization of C Array
Method 1:
int marks[5];

1
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

marks[0]=80;//initialization of array
marks[1]=60;
marks[2]=70;
marks[3]=85;
marks[4]=75;

Method 2:
int marks[5]={20,30,40,50,60};

Method 3:
int marks[]={20,30,40,50,60};

Program:

#include<stdio.h> int main() {


int n, sum = 0, c, array[100];
printf("Enter the number of values to be stored in array:\n"); scanf("%d", &n);
for (c = 0; c < n; c++)
{
scanf("%d", &array[c]); sum = sum + array[c];
}
printf("Sum = %d\n", sum); return 0;
}

Sample Input and Output:

Enter the number of values to be stored in array: 5 10 20 15 5 0


Sum = 50

2
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

List of experiments:

1. Write a program to reverse a given array.

3
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

4
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

2. Write a program to print sum of even and odd elements in an array.

5
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

3. Write a program to find the largest three elements in an array.

6
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

7
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

4. Write a program to read the total marks of n students in an array and print their ranks.

8
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

9
20CS1003L – Fundamentals of programming for URK21C
Problem Solving Lab S

OUTPUT :

Result:
The following program has been executed and verified.

10

You might also like