C Programming Project
1. Write a function that accepts a number n as input and returns the average of the sum of
numbers from 1 to n.
int avg(int n)
for(i=1;i<=n;i++)
sum=sum+i;
a=sum/(n);
return (a);
2. Write a program to transpose a 3x3 matrix using C program.
#include <stdio.h>
void main()
int c, d, matrix[3][3], transpose[3][3];
printf("Enter the elements of matrix\n");
for (c = 0; c < 3; c++)
for(d = 0; d < 3; d++)
scanf("%d",&matrix[c][d]);
for (c = 0; c < 3; c++)
for( d = 0 ; d < 3 ; d++ )
transpose[d][c] = matrix[c][d];
printf("Transpose of entered matrix :-\n");
for (c = 0; c < 3; c++) {
for (d = 0; d < 3; d++)
printf("%d\t",transpose[c][d]);
printf("\n");
OUTPUT
Enter the elements of matrix
1 2 3
4 5 6
7 8 9
Transpose of entered matrix:-
1 4 7
2 5 8
3 6 9
3. Write a program to check whether 3 is present in arr[]={1,2,3,4,5,6,7,8}
#include<stdio.h>
void main()
int i,m,flag=0;
int arr[]={1,2,3,4,5,6,7,8};
printf("Enter the element you want to search \n");
scanf("%d", &m);
for (i=0; i<8; i++)
if(arr[i]==m)
flag=1;
break;
if(flag==0)
printf("Not present");
else
printf("Present");