You are on page 1of 3

LIST OF PROGRAMS- ASSIGNMENT 5

ARRAYS

Q1. Write a program in C to read 5 number of values in an array and display it in


reverse order.
Q2. Write a Program to read prices of 5 items in an array and then display sum of all
prices, product of all prices and average of them.
Q3. Write a program in C to copy the elements of one array into another array.
Q4. .Write a program in C to find the maximum and minimum element in an array.
Q5. Write a program in C to read an array of 10 integers and count total no of even
and odd elements.
Q6. Write a program to enter marks of 10 students and search for a specific mark and
display its position. Also display the error if the element is not found. ( Linear search )
Q7. Write a program in C to read two arrays of size 5 and store sum of these arrays
into 3rd array.
Q8. Write a program in C to sort elements of array in ascending order. ( using bubble
sort ).
Q9. Write a program to explain use of string with scanf that discards all words after
blank spaces.

Q10. Write a program to explain use of string with gets and puts to display
sentence with blank spaces

Q11. Write a program to explain the use of string with fgets and fputs to
display the sentence with blank spaces. ( bcz gets, puts can cause data loss )

Q12. Write a program to read the marks of 02 students in three subjects ( 2D


array ) and display the marks.

Q13. Write a program to read sales of 2 salesmen in 3 months and to print total
sales made by each salesman. ( i=2 , j=3 )

Q14. Write a program to add two matrices . ( size of two matrices should be
same )

Q15. Write a program to subtract two matrices . ( size of two matrices should
be same ). Row and column should be same for both matrices.

Q16. Write a program to transpose a matrix .( here row elements become


column elements and column elements become row elements ).

Q17. Write a program to find the sum of elements of right diagonal matrix.
( Hint : both I and j is same ) TAKE 3*3 MATRIX
Q18. Write a program to replace all elements of right diagonal matrix to zero.
( Hint : both I and j is same ).TAKE 3*3 MATRIX

Q19. Write a program to replace all elements of left diagonal matrix to zero.
( Hint : As I increases,j decreases ).TAKE 3*3 MATRIX

Q20. Write a program to find the sum of all elements of left diagonal matrix . (
Hint : As I increases,j decreases ).TAKE 3*3 MATRIX.

Q21. Write a program to multiply two matrices .( Let A=3*2, B=2*3 )

Find the output of the following codes ( some examples for practice )

1.
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}

2.
#include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
}

3.
int main()
{
int arr[5], i=0;
while(i<5)
{
arr[i]=++i;
}
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
4.
int main ()
{
int foo [ ] = {16, 2, 77, 40, 5};
int n, result=0;
for ( n=0 ; n<5 ; ++n )
{
result += foo[n];
}
printf("Result is: %d", result);
return 0;
}

5.
int main()
{
int a[ ]={0,1,2,3,4,5,6,7,8,9,10};
int i=0,num;
num=a[++i+a[++i]]+a[++i];
printf("%d",num);
return 0;
}

You might also like