Professional Documents
Culture Documents
Data Structure and Algorithm
Data Structure and Algorithm
GA-1
Solution:-
Given,
LB=0
A[10]=2075
A[15]=2090
For A[10],
A[10]=B+[i-LB]*S
2075=B+10*S
S=[2075-B]/10 -(i)
For A[15],
A[15]=B+[i-LB]*S
2090=B+[15-0]*S
2090=B+15*S
S=[2090-B]/15
[2075-B]/10=[2090-B]/15
[2075-B]*15/10=2090-B
[2075-B]*3/2=2090-B
[2075-B]*3=[2090-B]*2
6225-3B=4180-2B
3B-2B=6225-4180
B=2045
S=[2075-B]/10
S=[2075-2045]/10
S=30/10
S=3
A[8]= B+[8-LB]*S
A[8]=2045+[8-0]*3
A[8]=2045+8*3
A[8]=2045+24
Example of array in c,
Output
Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
Average = 39
Example of Structure in c,
#include <stdio.h>
#include <string.h>
struct student
{
int id;
char name[20];
float percentage;
};
int main()
{
struct student record = {0}; //Initializing to null
record.id=1;
strcpy(record.name, "Raju");
record.percentage = 86.5;
printf(" Id is: %d \n", record.id);
printf(" Name is: %s \n", record.name);
printf(" Percentage is: %f \n", record.percentage);
return 0;
Output
Id is: 1
Name is: Raju
Percentage is: 86.500000