google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Wednesday, April 1, 2015

C program create a student struct accept details of n students into structure rearrange data in alphabetical order of stud name and display result.

Write a ‘C’ program to create a student structure having field stud name and address. Accept the details of ‘n’ students into the structure rearrange the data in alphabetical order of stud name and display the result.

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char sname[20];
char add[20];
};
void main()
{
struct student s[10];
char ch[20];
int i,j,n;
clrscr();
printf("enter the student");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the sname&add");
for(i=0;i<n;i++)
{
scanf("%s%s",&s[i].sname,&s[i].add);
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(&s[i].sname,&s[j].sname)>0)
{
strcpy(ch,&s[i].sname);
strcpy(&s[i].sname,&s[i].sname);
strcpy(&s[j].sname,ch);
}
}
}
for(i=0;i<n;i++)
{
printf("%s",s[i].sname);
}
getch();
}

C program to create student structure

Write a ‘C’ program to create student structure having field roll no, stud name,
class, pass this entire structure to function and display the structure elements.

#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char sname[20];
char sclass[10];
};
void disp(struct student);
void main()
{
struct student s;
clrscr();
printf("enter the rollno,sname&sclass");
scanf("%d%s%s",&s.rollno,&s.sname,&s.sclass);
disp(s);
getch();
}
void disp(struct student s)
{
printf("%d%s%s",s.rollno,s.sname,s.sclass);
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...