Wednesday, April 1, 2015

C program for 2-D array

Write a ‘C’ program to accept ‘n’ names from user store these name into
2-D array. Accept the name from user and search whether the name is
present in an array or not.

#include<stdio.h>
#include<conio.h>
void main()
{
char name[5][10],res[10];
int i,j,n;
clrscr();
printf("enter the no");
scanf("%d",&n);
printf("enter the matrix element");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%s",&name[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("enter the name");
scanf("%s",&res);
if(strcmp(&name[i][j],&res)!=0)
{
printf("name is not found");
break;
}
else
{
printf("name is found");
}
}
}
getch();
}

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();
}

Featured posts

सौंफ के फायदे

 सौंफ त्रिदोषनाशक है, इसकी तासीर ठंडी है, पर यह जठराग्नि को मंद नहीं करती।            आंखों की रोशनी सौंफ का सेवन करके बढ़ाया जा सकता है। सौ...

Popular posts