Professional Documents
Culture Documents
ARRAYS
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 )
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.
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.
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;
}