0% found this document useful (0 votes)
16 views12 pages

STRUCTURES

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views12 pages

STRUCTURES

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

STRUCTURES

#include <stdio.h>

struct student
{
char usn[50];
char name[50];
int marks;
} s[10];

int main()
{
int i, n, countav = 0, countbv = 0, sum = 0;
float average;

printf("Enter the number of students: ");


scanf("%d", &n);

printf("Enter the student details:\n");


for (i = 0; i < n; i++)
{
printf("Enter the USN: ");
scanf("%s", s[i].usn);
printf("Enter the name: ");
scanf("%s", s[i].name);
printf("Enter the marks: ");
scanf("%d", &s[i].marks);
printf("\n");

sum = sum + s[i].marks;


}

printf("Displaying information:\n");
for (i = 0; i < n; i++)
{
printf("USN: %s\n", s[i].usn);
printf("Name: %s\n", s[i].name);
printf("Marks: %d\n", s[i].marks);
printf("\n");
}

average = (float)sum / n; // Calculate average marks

printf("Average marks is: %.2f\n", average);


for (i = 0; i < n; i++)
{
if (s[i].marks > average)
{
countav++;
}
else
{
countbv++;
}
}

printf("The total number of students who scored above


average are: %d\n", countav);
printf("The total number of students who scored below
average are: %d\n", countbv);

return 0;
}
POINTERS
#include <stdio.h>
#include <math.h>
int main()
{
float a[10], *ptr, mean, std, sum=0,sumstd=0;
int i,n;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
{
scanf("%f",&a[i]);
}
ptr=a;
for(i=0;i<n;i++)
{
sum=sum+*ptr;
ptr++;
}
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
{
sumstd=sumstd+pow((*ptr-mean),2);
ptr++;
}
std=sqrt(sumstd/n);
printf("Sum: %.3f\t\n",sum);
printf("Mean: %.3f\t\n",mean);
printf("Standard Deviation: %.3f\t",std);
return 0;
}

MATRIX MULTIPLICATION
#include <stdio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
printf("Enter the number of rows and columns for first
matrix\n");
scanf("%d %d",&m,&n);
printf("Enter the number of rows and columns for second
matrix\n");
scanf("%d %d",&p,&q);
if(n==p)
{
printf("Enter the elements of first matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of second matrix\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("The matrix after multiplication is: \n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
else
{
printf("The multiplication is not possible");
}
}
STRING MANIPULATION
#include<stdio.h>
#include<string.h>

int length(char s1[]);


int compare(char s1[], char s2[]);
void concat(char s1[], char s2[]);

int main()
{
char s1[10], s2[10];
int len, res;

printf("Enter the string s1: \n");


scanf("%s", s1); // Removed & before s1 and s2

printf("Enter the string s2: \n");


scanf("%s", s2); // Removed & before s1 and s2

len = length(s1);
printf("The length of the string s1 is %d\n", len);
len = length(s2);
printf("The length of the string s2 is %d\n", len);

res = compare(s1, s2);


if (res == 0) // Changed = to ==
{
printf("The strings are equal\n");
}
else
{
printf("The strings are not equivalent\n");
}

concat(s1, s2);
printf("The concatenated string is %s\n", s1); // Added \n
at the end

return 0;
}

int length(char s1[])


{
int len = 0;
while (s1[len] != '\0')
{
len++;
}
return len; // Removed unnecessary parentheses
}

int compare(char s1[], char s2[])


{
int count = 0;
while (s1[count] == s2[count])
{
if (s1[count] == '\0')
{
return 0; // Strings are equal
}
count++;
}
return -1; // Strings are not equal
}
void concat(char s1[], char s2[])
{
int i, j;
i = strlen(s1);
for (j = 0; s2[j] != '\0'; i++, j++)
{
s1[i] = s2[j];
}
s1[i] = '\0';
}

SINE SERIES
#include<stdio.h>
#include<stdlib.h>
int main()
{
float degree,nume,deno,value,terms,x;
int n,i;
printf("Enter the number of terms:\n");
scanf("%d",&n);
printf("Enter the degree:\n");
scanf("%f",&degree);
x=degree*(3.14156/180);
value=0.0;
nume=x;
deno=1;
terms=nume/deno;
for(i=1;i<=n;i++)
{
value=value+terms;
nume=-nume*x*x;
deno=deno*(2*i)*(2*i+1);
terms=nume/deno;
}
printf("Calculated value of sin(%f) is %f\n",degree,value);
printf("Corrected value of sin(%f) is %.3f\n",degree,x);
return 0;

You might also like