CPGM 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Expt. No.

Date:

14. LENGTH OF THE STRING WITHOUT STRLEN() FUNCTION

AIM

ALGORITHM

PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built-in function for IO
int main()
{
char s1[50];
int length, j;
printf("\n\t\t\tLENGTH OF THE STRING WITHOUT USING STRLEN()");
printf("\n\t\t\t*******************************************");
printf("\n Enter string :");
fgets(s1,50,stdin);
length = 0;
while (s1[length] != '\0' &&s1[length]!='\n')
{

21
++length;
}
s1[length]='\0';
printf("Length of the string %s is %d",s1,length);
getch();
}
SAMPLE INPUT/OUTPUT

RESULT

22
Expt. No. Date:

15. FREQUENCY OF A CHARACTER IN THE STRING

AIM

ALGORITHM

23
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built
built-in function for IO
#include <string.h>
int main()
{
char mystr[50],c;
int i,freq=0;
printf("\n\t\t\tFREQUENCY OF A CHARACTER IN THE STRING");
printf("\n\t\t\t**************************************
t********************************************");
printf("\nEnter the string: ");
fgets(mystr,sizeof(mystr),stdin);
printf("\nn Enter the character to find the frequency: ");
scanf("%c",&c);
for(i=0;mystr[i]!='\n';i++)
{
if(mystr[i]==c)
{
freq++;
}
}
printf("\nn The frequency of the character \'%c\' in the string \"%s\"" is %d",c,mystr,freq) ;
getch();
}

SAMPLE INPUT/OUTPUT

RESULT

24
Expt. No. Date:

16. STORE STUDENT INFORMATION IN STRUCTURE AND DISPLAY IT

AIM

ALGORITHM

25
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built-in function for IO
#include <stdlib.h>
struct student
{
char name[30];
int rno;
int marks[5];
int total;
float avg;
};
int main()
{
struct student S;
printf("\n\t\t\tSTUDENT INFORMATION");
printf("\n\t\t\t*******************");
printf("\n Enter the name of the student: ");
fgets(S.name,30,stdin);
printf("\n Enter the Rollno: ");
scanf("%d",&S.rno);
S.total=0;
for(int i=0;i<5;i++)
{
printf("\n Enter Mark %d: ", i+1);
scanf("%d",&S.marks[i]);
S.total += S.marks[i];
}
S.avg=(float)S.total/5.0;
printf("\nName: %s \nRoll NO:%d",S.name,S.rno);
for(int i=0;i<5;i++)
{
printf(" \nMark %d:%d", i+1,S.marks[i]);
}
printf("\n Total Marks:%d \nAverage Marks: %0.2f",S.total,S.avg);
getch();
}

26
SAMPLE INPUT/OUTPUT

RESULT

27
Expt. No. Date:

17. IMPLEMENT ARRAY OF STRUCTURES

AIM

ALGORITHM

28
PROGRAM
#include<stdio.h>//defines standard IO operations
#include<conio.h>//used to access many built-in function for IO
#include <stdlib.h>
#define MAX 3
struct student
{
int rno;
int marks[5];
int total;
};
int main()
{
struct student S[MAX];
int i,j,total_m[MAX],highest,topscorer;
printf("\n\t\t\tIMPLEMENT ARRAY OF STRUCTURES");
printf("\n\t\t\t*****************************");
for(j=0;j<MAX;j++)
{
printf("\n Enter the Rollno: ");
scanf("%d",&S[j].rno);
S[j].total=0;
for (i=0;i<5;i++)
{
printf("\n Enter Mark %d: ", i+1);
scanf("%d",&S[j].marks[i]);
S[j].total += S[j].marks[i];
}
total_m[j]=S[j].total;
printf("\n Student %d Total Marks:%d ",j+1,S[j].total);
}

for(i=0;i<5;i++)
{
highest=0;
for(j=0;j<MAX;j++)
{
if(highest<S[j].marks[i])
{

29
highest=S[j].marks[i];
topscorer=j;
}
}
printf("\n Highest mark in Subject %d is %d scored by Student %d", i+1, highest,
S[topscorer].rno);
}
highest=0;
for(j=0;j<MAX;j++)
{
if(highest<total_m[j])
{
highest=total_m[j];
topscorer=j;
}
}
printf("\n Student %d has scored the highest total marks of %d", S[topscorer].rno, highest);
getch();
}

30

You might also like