Académique Documents
Professionnel Documents
Culture Documents
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();
}
4.
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();
}
6.
#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.
#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.
#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;
}