0% found this document useful (0 votes)
24 views

C Programming

The document describes 3 C programming projects: 1) A function to calculate the average of numbers from 1 to n, 2) A program to transpose a 3x3 matrix, 3) A program to check if a given number is present in an array.

Uploaded by

DurbaGhosh
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)
24 views

C Programming

The document describes 3 C programming projects: 1) A function to calculate the average of numbers from 1 to n, 2) A program to transpose a 3x3 matrix, 3) A program to check if a given number is present in an array.

Uploaded by

DurbaGhosh
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/ 3

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");

You might also like