Vous êtes sur la page 1sur 10

1.

/*program to enter 30 numbers and to tell how


many times
the number to be searched is entered*/
#include<conio.h>
#include<stdio.h>
main()
{
int a[30],lc=0,n;
clrscr();
for(int i=0;i<30;i++)
{
printf("\nEnter the %dth number:",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter the number to be searched: ");
scanf("%d",&n);
for(int j=0;j<30;j++)
{
if(n==a[j])
lc++;
}
if(lc!=0)
printf("\n%d is present %d times",n,lc);
else
printf("%d is not present",n);
getch();
}

2(A).
/*program to enter the salesman id, average
feedback for
every salesman and the average feedback */
#include<conio.h>
#include<stdio.h>
main()
{
int noc,id,arr[11][8],olc,ilc,feed;
float sum=0,avg;
clrscr();
for(olc=0;olc<8;olc++)
{
printf("\nEnter the salesman id: ");
scanf("%d",&arr[0][olc]);
printf("\nEnter the number of customers(max. 10): ");
scanf("%d",&noc);

for(ilc=1;ilc<=noc;ilc++)
{
printf("Enter your feedback: ");
scanf("%d",&arr[ilc][olc]);
sum=sum+arr[ilc][olc];
}
avg=(float)sum/noc;
printf("Average feedback for salesman id %d is %1.2f",arr[0][olc],avg);
avg=0;
sum=0;
}
getch();
}

2(B).
/*program to find highest and lowest feedback
from the entered
feedbacks for individual salesman id's*/
#include<conio.h>
#include<stdio.h>
main()
{
int noc,id,arr[11][8],olc,ilc,feed,max,min,k,l,m;
float sum=0,avg[8];
clrscr();
printf("\nEnter the number of customers(max. 10): ");
scanf("%d",&noc);
for(olc=0;olc<8;olc++)
{
printf("\nEnter the salesman id: ");
scanf("%d",&arr[0][olc]);
for(ilc=1;ilc<=noc;ilc++)
{
printf("Enter your feedback: ");
scanf("%d",&arr[ilc][olc]);
sum=sum+arr[ilc][olc];
}
avg[olc]=(float)sum/noc;
printf("Average feedback for salesman id %d is %1.2f",arr[0][olc],avg[olc]);
sum=0;
}
max=0;min=5;
for(m=0;m<8;m++)
{
if(avg[m]>max)
{max=avg[m];
k=m;}
else if(avg[m]<min)
{min=avg[m];

l=m;}
}
printf("\nSalesman with id %d has highest feedback",arr[0][k]);
printf("\nSalesman with id %d has least feedback",arr[0][l]);
getch();
}

3. //program to accept ids and job bands and tell the


no. of employees with the accepted id that was entered
#include<conio.h>
#include<stdio.h>
main()
{
int i=0,eid[]={1500,1600,1700,1800,1900,2000},lc=0;
char job_band[6],id;
printf("Enter the job bands only from among 'D','T','C','M','B'");
while(i<6)
{
printf("\nEnter the job band for the employee with id %d: ",eid[i]);
scanf("%c",&job_band[i]);
fflush(stdin);
i++;
}
printf("\nEnter id to be searched: ");
scanf("%c",&id);
for(i=0;i<6;i++)
{
if(id==job_band[i])
lc=lc+1;
}
printf("Number of confirmed employees with %c job band are %d",id,lc);
getch();
}

4.

/*program to find how many numbers entered are

positive and negative*/


#include<conio.h>
#include<stdio.h>
main()
{
clrscr();
int arr[200],n,pc=0,nc=0;
printf("How many numbers you want to enter (max. 200): ");

scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
for(int j=0;j<n;j++)
{
if(arr[j]>=0)
pc++;
else
nc++;
}
printf("Out of %d entered numbers, %d are positive and %d are
negative",n,pc,nc);
getch();
}

5. /*program to find highest marks from the entered


names and marks*/
#include<stdio.h>
#include<conio.h>
main()
{
char stu[7];
int max=0,marks[7][7],sum=0,m;
clrscr();
for(int i=0;i<5;i++)
{
printf("Enter the name of student:\n");
scanf("%s",stu[i]);
printf("Enter marks in 5 subjects for %s: ",stu[i]);
for(int j=0;j<5;j++)
{
scanf("%d",&marks[i][j]);
sum=sum+marks[i][j];
}
if(sum>max)
{ max=sum;
m=i;
}
sum=0;
fflush(stdin);
}
printf(" %s has highest marks and highest marks are %d",stu[m],max);
getch();
return 0;
}

6.

//program to merge two sorted arrays

#include<stdio.h>
#include<conio.h>
main()
{
int a[30],b[30],c[60],h,i,j,l,m,n,k;
printf("Enter the number of elements in A(max.30):\n");
scanf("%d",&m);
printf("Enter the elements in sorted order:\n");
for(i=0;i<m;i++)
scanf("%d",&a[i]);
printf("Enter the number of elements in B(max.30):\n");
scanf("%d",&n);
printf("Enter the elements in sorted order:\n");
for(j=0;j<n;j++)
scanf("%d",&b[j]);
i=0,j=0,h=0;
while(i<m||j<n)
{
if(a[i]<=b[j])
{
c[h]=a[i];
i++;
}
else
{c[h]=b[j];
j++;
}
h++;
}
if(i==m)
for(l=0;l<m;l++)
c[h++]=b[l];
else if(j==n)
for(k=0;k<n;k++)
c[h++]=a[k];
printf("After merging elements are:\n");
for(i=(m+n-1);i>=0;i--)
printf("%d ",c[i]);
getch();
return 0;
}

7(A).
//program to enter the student ids and search
the entered id
#include<stdio.h>

#include<conio.h>
#include<stdlib.h>
int main()
{
int id,id_co[2][5]={0,0,0,0,0,0,0,0,0,0},cid[2][5]={0,0,0,0,0,0,0,0,0,0},lc=0;
printf("Enter the student ids:\n");
for(int i=0;i<5;i++)
scanf("%d",&id_co[0][i]);
printf("\nEnter the student id to be searched:\t");
scanf("%d",&id);
for(int i=0;i<5;i++)
{
if(id!=id_co[0][i])
lc++;
}
if(lc==5)
{
printf("ERROR: Id does not exist\n");
exit(0);
}
else if(lc<5)
printf("Id exists\n");
getch();
return 0;
}

7(B).
//program to check whether the entered
semester is current or not
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int id,id_co[2][5]={0,0,0,0,0,0,0,0,0,0},cid[2][5]={0,0,0,0,0,0,0,0,0,0},lc=0;
printf("Enter the student ids:\n");
for(int i=0;i<5;i++)
scanf("%d",&id_co[0][i]);
printf("\nEnter the student id to be searched:\t");
scanf("%d",&id);
for(i=0;i<5;i++)
{
if(id!=id_co[0][i])
lc++;
}
if(lc==5)
printf("ERROR: Id does not exist");
else if(lc<5)
printf("Id exists");

int sem;
printf("Enter the semester:\t");
scanf("%d",&sem);
if(sem!=1)
printf("ERROR: Please enter the current semester");
else printf("Current semester");
getch();
return 0;
}

7(C).
//program to store student id and display
message for the searched id
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int id,cid[2][5]={0,0,0,0,0,0,0,0,0,0},lc=0;
for(int i=0;i<2;i++)
{
printf("Enter the student ids for %d semester:\n",i+1);
for(int j=0;j<5;j++)
scanf("%d",&cid[i][j]);
}
printf("Enter the student id to be searched:\t");
scanf("%d",&id);
for(i=0;i<5;i++)
{
if(id!=cid[0][i])
lc++;
}
if(lc==5)
printf("ERROR: ID does not exist\n");
else
printf("ERROR: ID already exists");
getch(); return 0;
}

7(D).
//program to store the course ids and display
the message for searched course id
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int id,cid[2][5]={0,0,0,0,0,0,0,0,0,0},lc=0;
for(int i=0;i<2;i++)

{
printf("Enter the course ids for %d semester:\n",i+1);
for(int j=0;j<5;j++)
scanf("%d",&cid[i][j]);
}
printf("Enter the course id to be searched:\t");
scanf("%d",&id);
for(i=0;i<5;i++)
{
if(id!=cid[0][i])
lc++;
}
if(lc==5)
printf("ERROR: Course Id does not belong to current semester\n");
getch(); return 0;}

8.

//program to find sum of upper triangular matrix

#include<conio.h>
#include<stdio.h>
int main()
{
int matrix[3][3],sum=0;
clrscr();
printf("Enter the 3 X 3 matrix:\n");
for(int olc=0;olc<3;olc++)
for(int ilc=0;ilc<3;ilc++)
scanf("%d",&matrix[olc][ilc]);
sum=matrix[0][1]+matrix[0][2]+matrix[1][2];
printf("Sum of upper triangular matrix is %d",sum);
getch();
}

9.

//program to sort names alphabetically

#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
clrscr();
char list[20][20],tname[20][20],temp[20];
int num,i,j;
printf("Enter the number of elements(max. 20):\n");
scanf("%d",&num);
printf("Enter the elements:\n");

for(i=0;i<num;i++) {
scanf("%s",&list[i]);
strcpy(tname[i],list[i]);}
for(i=0;i<num;i++)
for(j=i+1;j<num;j++)
if(strcmp(list[i],list[j])>0)
{
strcpy(temp,list[i]);
strcpy(list[i],list[j]);
strcpy(list[j],temp);
}
printf("After sorting elements are\n");
for(i=0;i<num;i++)
printf("%s\n",list[i]);
getch();
return 0;
}

10. //program to multiply two matrices


#include<conio.h>
#include<stdio.h>
int main()
{
clrscr();
int m1,m2,n1,n2;
printf("Enter the order of 1st matrix:\t");
scanf("%d %d",&m1,&m2);
printf("Enter the order of 2nd matrix:\t");
scanf("%d %d",&n1,&n2);
int M[10][10],N[10][10],P[10][10];
if(m2!=n1)
printf("Matrices can't be multiplied\n");
else if(m2==n1)
{
printf("\nEnter the 1st matrix:\n");
for(int i=0;i<m1;i++)
{
for(int j=0;j<m2;j++)
scanf("%d",&M[i][j]);
}
printf("\nEnter the 2nd matrix:\n");
for(i=0;i<n1;i++)
{
for(int j=0;j<n2;j++)
scanf("%d",&N[i][j]);
}
for(i=0;i<m1;i++)
for(int j=0;j<n2;j++)
for(int k=0;k<n1;k++)
P[i][j]=P[i][j]+M[i][k]*N[k][j];

printf(" The result of matrix multiplication is :\n");


for(i=0;i<m1;i++)
{for(j=0;j<n2;j++)
printf("%d ",P[i][j]);
printf("\n");
}
}
getch();
return 0;
}

Vous aimerez peut-être aussi