Example 1:-
#include<stdio.h> #include<conio.h> struct student { int sno; char sname[20]; int age; }s[4]; void main() { struct student s[4]={ {101,"Prasad",17}, {102,"Vineela",15}, {103,"Lakshmi",16}, {104,"Sanker",18}, }; int i; clrscr(); for(i=0;i<=3;i++) { printf("Student Number : %d\n",s[i].sno); printf("Student Name : %s\n",s[i].sname); printf("Student age : %d\n\n",s[i].age); } getch(); } |
Output :-
Example 2:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct sample
{
char word[10];
char mean[10];
}s[4];
void main()
{
struct sample s[4]={
{"cop","police"},
{"home","house"},
{"begin","start"},
{"find","search"},
};
int i,tag,k;
char x[10];
clrscr();
printf("Enter a word:");
scanf("%s",&x);
for(i=0;i<=3;i++)
{
k=strcmpi(x,s[i].word);
if(k==0)
{
tag=9;
break;
}
}
if(tag==9)
printf("It means:%s\n",s[i].mean);
else
printf("The word not Found");
getch();
}
|
Output:-
Example 3:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct sample
{
char word[10];
char mean[10];
}s[4];
void main()
{
struct sample s[4]={
{"cop","police"},
{"home","house"},
{"begin","start"},
{"find","search"},
};
int i,tag,k,t;
char x[10];
clrscr();
printf("Enter a Word or Mean:");
scanf("%s",&x);
for(i=0;i<=3;i++)
{
k=strcmpi(x,s[i].word);
t=strcmpi(x,s[i].mean);
if(k==0)
{
tag=9;
break;
}
{
if(t==0)
{
tag=10;
break;
}
}
}
if(tag==9)
printf("It means:%s\n",s[i].mean);
else if(tag==10)
printf("It words:%s\n",s[i].word);
else
printf("The word not Found");
getch();
}
|
Output:-
Example 4:-
#include<stdio.h>
#include<conio.h>
struct student
{
int sno,c,cpp,java,tot;
float avg;
char sname[20],grd;
}s[4];
void main()
{
struct student s[4];
int i;
clrscr();
for(i=0;i<=3;i++)
{
printf("Enter Student no & name:");
scanf("%d%s",&s[i].sno,&s[i].sname);
printf("Enter student Marks:");
scanf("%d%d%d",&s[i].c,&s[i].cpp,&s[i].java);
}
for(i=0;i<=3;i++)
{
s[i].tot=s[i].c+s[i].cpp+s[i].java;
s[i].avg=s[i].tot/3.0;
if(s[i].c>=35&&s[i].cpp>=35&&s[i].java>=35)
{
if(s[i].avg>=70)
s[i].grd='A';
else if(s[i].avg>=50)
s[i].grd='B';
else if(s[i].avg>=40)
s[i].grd='C';
else
s[i].grd='D';
}
else
{
s[i].grd='F';
}
}
clrscr();
printf("\t\tStudent Marks Table\n");
printf("\t\t======= ===== =====\n");
printf("Sno\tSname\tC\tCpp\tJava\tTotal\tAvg\tGrade\n");
printf("---\t-----\t--\t---\t---\t-----\t---\t-----\n");
for(i=0;i<=3;i++)
printf("%d\t%s\t%d\t%d\t%d\t%d\t%.2f\t%c\n",
s[i].sno,s[i].sname,s[i].c,s[i].cpp, s[i].java,s[i].tot,s[i].avg,s[i].grd);
}
getch();
}
|
Output:-
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Post a Comment