Sie sind auf Seite 1von 3

Question 1 .

Train searching
Solution-----
#include<stdio.h>
#include<conio.h>
int main()
{
int train[5],n,i, flag = 0;
for(i=0;i<5;i++)
{
printf("enter the train no.");
scanf("%d",&train[i]);
}
printf("enter the train no. to be searched");
scanf("%d",&n);
for(i=0;i<5;i++)
{
if(n==train[i])
{
flag = 1;
}
}

if(flag)
{
printf("train available");
}
else
{
printf("train unavailable");
}
return 0;
getch();
}
Output---------
enter the train no.11
enter the train no.22
enter the train no.33
enter the train no.44
enter the train no.55
enter the train no. to be searched22
Train available
--------------------------------
Question 2. Students marks
Solution--------- #include<stdio.h>
#include<conio.h>
int main()
{
printf("enter the no. of students:\n");
int n;
int temp,i,j;
scanf("%d",&n);
int a[n];
printf("enter the marks of the students:\n");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{


for( j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;

}
}
}
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);


}
getch();
}
Output--------------
enter the no. of students:
5
enter the marks of the students:
45
67
89
98
78
45 67 78 89 98

Das könnte Ihnen auch gefallen