Академический Документы
Профессиональный Документы
Культура Документы
Output:-
Enter no of students: 5
Student 1:
Enter roll: 1
Enter name: Rajdip
Enter marks 1: 79
Enter marks 2: 81
Enter marks 3: 92
Student 2:
Enter roll: 2
Enter name: Rimpa
Enter marks 1: 76
Enter marks 2: 80
Enter marks 3: 72
Student 3:
Enter roll: 3
Enter name: Suman
Enter marks 1: 75
Enter marks 2: 65
Enter marks 3: 81
Student 4:
Enter roll: 4
Enter name: Arnab
Enter marks 1: 90
Enter marks 2: 81
Enter marks 3: 76
Student 5:
Enter roll: 5
Enter name: Aniket
Enter marks 1: 67
Enter marks 2: 76
Enter marks 3: 80
2. Rewrite the above program and print the name of the topper among all students.
->
#include <stdio.h>
struct student
{
int roll;
char name[20];
int marks[3];
int totmarks;
};
main()
{
int i,j,n,pos;
printf("Enter no of students: ");
scanf("%d",&n);
struct student s1[n];
for(j=0;j<n;j++)
{
printf("\nStudent %d: \n",j+1);
printf("Enter roll: ");
scanf("%d",&s1[j].roll);
printf("Enter name: ");
scanf("%s",s1[j].name);
s1[j].totmarks=0;
for(i=0;i<3;i++)
{
printf("Enter marks %d: ",i+1);
scanf("%d",&s1[j].marks[i]);
s1[j].totmarks+=s1[j].marks[i];
}
}
printf("\nThe entered information are:\n\n");
printf("Roll\tName\tMarks 1\tMarks 2\tMarks 3\tTotal\n");
printf("---------------------------------------------------------------\n");
for(j=0;j<n;j++)
{
printf("%d\t\t%s\t\t",s1[j].roll,s1[j].name);
for(i=0;i<3;i++)
{
printf("%d\t\t",s1[j].marks[i]);
}
printf("%d\n",s1[j].totmarks);
}
pos=0;
for(i=1;i<n;i++)
{
if(s1[i].totmarks>s1[pos].totmarks)
pos=i;
}
printf("\nThe name of the topper is: %s",s1[pos].name);
}
Output:-
Enter no of students: 3
Student 1:
Enter roll: 1
Enter name: Rajdip
Enter marks 1: 79
Enter marks 2: 81
Enter marks 3: 92
Student 2:
Enter roll: 2
Enter name: Rimpa
Enter marks 1: 76
Enter marks 2: 80
Enter marks 3: 72
Student 3:
Enter roll: 3
Enter name: Suman
Enter marks 1: 75
Enter marks 2: 65
Enter marks 3: 81
Student 4:
Enter roll: 4
Enter name: Arnab
Enter marks 1: 90
Enter marks 2: 81
Enter marks 3: 76
Student 5:
Enter roll: 5
Enter name: Aniket
Enter marks 1: 67
Enter marks 2: 76
Enter marks 3: 80
printf("%d\t%s\t%s\t%f\t%d\n",s1[i].empid,s1[i].ename,s1[i].job,s1[i].sal,s1[i].deptid);
}
}
main()
{
int ch,i,n,a,b;
printf("Enter the no of employees: ");
scanf("%d",&n);
struct employee s1[n];
for(i=0;i<n;i++)
{
printf("\n-----Employee %d-----\n",i+1);
printf("Enter employees ID: ");
scanf("%d",&s1[i].empid);
printf("Enter name: ");
scanf("%s",s1[i].ename);
printf("Enter employee's job (designation): ");
scanf("%s",s1[i].job);
printf("Enter salary of the employee: ");
scanf("%f",&s1[i].sal);
printf("Enter department ID of the employee: ");
scanf("%d",&s1[i].deptid);
}
do
{
printf("\n\n---------------------MENU-----------------------\n");
printf("\n 1.Display all employees records");
printf("\n 2.Display the employees having given salary range");
printf("\n 3.Display the employee whose depart id is 10 and having salary greater
than 10000");
printf("\n 4.Display the employees who are typists");
printf("\n 5.Display the highest & lowest salary paid employee");
printf("\n 0.Exit");
printf("\n\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
display(s1,n);
break;
case 2:
printf("Enter the salary range: ");
scanf("%d%d",&a,&b);
dissal_spcrange(s1,n,a,b);
break;
case 3:
dis_dept10sal(s1,n);
break;
case 4:
dis_typist(s1,n);
break;
case 5:
dis_highlowsal(s1,n);
break;
case 0:
printf("\n--------------End-------------\n");
break;
default:
printf("\n---------INVALID CHOICE-----------");
printf("\n-----------Try Again-------------\n");
}
}while (ch);
}
Output:-
Enter the no of employees: 5
-----Employee 1-----
Enter employees ID: 1
Enter name: Rajdip
Enter employee's job (designation): Analyst
Enter salary of the employee: 20000
Enter department ID of the employee: 14
-----Employee 2-----
Enter employees ID: 2
Enter name: Nilanjan
Enter employee's job (designation): Typist
Enter salary of the employee: 9000
Enter department ID of the employee: 13
-----Employee 3-----
Enter employees ID: 3
Enter name: Rimpa
Enter employee's job (designation): Developer
Enter salary of the employee: 15000
Enter department ID of the employee: 10
-----Employee 4-----
Enter employees ID: 4
Enter name: Arnab
Enter employee's job (designation): Supervisor
Enter salary of the employee: 16000
Enter department ID of the employee: 12
-----Employee 5-----
Enter employees ID: 5
Enter name: Aniket
Enter employee's job (designation): Typist
Enter salary of the employee: 8000
Enter department ID of the employee: 11
-----Employee 6-----
Enter employees ID: 6
Enter name: Hritwick
Enter employee's job (designation): Officer
Enter salary of the employee: 30000
Enter department ID of the employee: 16
-----Employee 7-----
Enter employees ID: 7
Enter name: Shamayita
Enter employee's job (designation): Typist
Enter salary of the employee: 9000
Enter department ID of the employee: 20
-----Employee 8-----
Enter employees ID: 8
Enter name: Shreya
Enter employee's job (designation): Clerk
Enter salary of the employee: 15000
Enter department ID of the employee: 21
-----Employee 9-----
Enter employees ID: 9
Enter name: Nabin
Enter employee's job (designation): Clerk
Enter salary of the employee: 16000
Enter department ID of the employee: 17
-----Employee 10-----
Enter employees ID: 10
Enter name: Utsab
Enter employee's job (designation): Analyst
Enter salary of the employee: 9000
Enter department ID of the employee: 19
---------------------MENU-----------------------
0.Exit
---------------------MENU-----------------------
---------------------MENU-----------------------
---------------------MENU-----------------------
---------INVALID CHOICE-----------
-----------Try Again-------------
---------------------MENU-----------------------
1.Display all employees records
2.Display the employees having given salary range
3.Display the employee whose depart id is 10 and having salary greater than 10000
4.Display the employees who are typists
5.Display the highest & lowest salary paid employee
0.Exit
4. Rewrite the above structure by making member sal as a nested structure as follows:
{
int basis;
int da;
int hra;
int city;
}sal;
Now enter information for n employees and print their details.
include <stdio.h>
struct employee
{
int empid; //employee id
char ename[20]; //name
char job[15]; //designation
struct sal; //salary
int deptid; //dept id where the emp works
struct{
int basic;
int da;
int hra;
int city;
}sal;
};
main()
{
int i,n;
printf("Enter the no of employees: ");
scanf("%d",&n);
struct employee s1[n];
for(i=0;i<n;i++)
{
printf("\n-----Employee %d-----\n",i+1);
printf("Enter employees ID: ");
scanf("%d",&s1[i].empid);
printf("Enter name: ");
scanf("%s",s1[i].ename);
printf("Enter employee's job (designation): ");
scanf("%s",s1[i].job);
printf("Enter basic amount: ");
scanf("%d",&s1[i].sal.basic);
printf("Enter DA amount: ");
scanf("%d",&s1[i].sal.da);
printf("Enter HRA amount: ");
scanf("%d",&s1[i].sal.hra);
printf("Enter city allownance amount: ");
scanf("%d",&s1[i].sal.city);
printf("Enter department ID of the employee: ");
scanf("%d",&s1[i].deptid);
}
printf("\nThe entered information are:\n");
printf("Emp. ID\tName\tDesignation\tBasic\tDA\tHRA\tCity\t Dept. ID\n");
printf("-------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t\t%s\t\t%s\t\t%d\t%d\t%d\t%d\t%d\n",s1[i].empid,s1[i].ename,s1[i].job
,
s1[i].sal.basic,s1[i].sal.da,s1[i].sal.hra,s1[i].sal.city,s1[i].deptid);
}
}
Output:-
Enter the no of employees: 3
-----Employee 1-----
Enter employees ID: 1
Enter name: Rajdip
Enter employee's job (designation): Manager
Enter basic amount: 400
Enter DA amount: 200
Enter HRA amount: 500
Enter city allownance amount: 600
Enter department ID of the employee: 10
-----Employee 2-----
Enter employees ID: 28
Enter name: Suman
Enter employee's job (designation): Typist
Enter basic amount: 400
Enter DA amount: 500
Enter HRA amount: 600
Enter city allownance amount: 700
Enter department ID of the employee: 11
-----Employee 3-----
Enter employees ID: 3
Enter name: Nilanjan
Enter employee's job (designation): Analyst
Enter basic amount: 300
Enter DA amount: 500
Enter HRA amount: 600
Enter city allownance amount: 200
Enter department ID of the employee: 12
->
#include<stdio.h>
struct cust
{
int accno;
int pin; //4 digit number to access ATM
char name[20];
int amt;
};
printf("\n\n---Account Information---\n\n");
printf("AccNo\tPin\tName\tBalance\n");
printf("-----------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%s\t%d\n",c[i].accno,c[i].pin,c[i].name,c[i].amt);
do
{
printf("--------------------\n");
printf("---WELCOME TO ATM---\n");
printf("--------------------\n\n");
printf("Enter your Account No: ");
scanf("%d\n",&acc);
printf("Enter pin: ");
scanf("%d\n\n",&p);
printf("1. Deposit\n");
printf("2. Withdrawl\n");
printf("3. Check Balance\n");
printf("4. Change Pin\n");
printf("0. Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
deposit(c,n,acc,p);
break;
case 2:
withdraw(c,n,acc,p);
break;
case 3:
balance_enq(c,n,acc,p);
break;
case 4:
change_pin(c,n,acc,p);
case 0:
printf("\nTransaction Complete\n");
printf("\n--Have a nice day---");
break;
default:
printf("\n---Invalid choice\nTry Again---\n");
}
}while(ch);
}
Output:-
----Customer 1-----
Enter Account number: 10026
Enter pin: 1234
Enter Customer Name: Rajdip
Enter initial balance: 3400
----Customer 2-----
Enter Account number: 10027
Enter pin: 3456
Enter Customer Name: Nilanjan
Enter initial balance: 5400
----Customer 3-----
Enter Account number: 10028
Enter pin: 3367
Enter Customer Name: Aniket
Enter initial balance: 6100
----Customer 4-----
Enter Account number: 10029
Enter pin: 8921
Enter Customer Name: Rimpa
Enter initial balance: 4300
----Customer 5-----
Enter Account number: 10030
Enter pin: 8820
Enter Customer Name: Sougata
Enter initial balance: 7100
---Account Information---
--------------------------------
---WELCOME TO ATM---
--------------------------------
Enter your Account No: 10027
Enter pin: 3456
1. Deposit
2. Withdrawl
3. Check Balance
4. Change Pin
0. Exit
Enter your choice: 1
-----DEPOSIT-----
Enter amount to Diposit: 1200
----Deposit Successful----
--------------------------------
---WELCOME TO ATM---
--------------------------------
Enter your Account No: 10027
Enter pin: 3456
1. Deposit
2. Withdrawl
3. Check Balance
4. Change Pin
0. Exit
Enter your choice: 3
----Balance Enq.----
Your initial balance is 6600
--------------------------------
---WELCOME TO ATM---
--------------------------------
Enter your Account No: 10029
Enter pin: 8921
1. Deposit
2. Withdrawl
3. Check Balance
4. Change Pin
0. Exit
Enter your choice: 4
----CHANGE PIN----
Enter the new pin: 4546
----Pin Changed Successful----
----WITHDRAW----
Enter amount to Withdraw: 3400
->
#include <stdio.h>
union student
{
int roll;
char name[20];
float marks;
};
main()
{
union student s;
printf("Enter roll: ");
scanf("%d ",&s.roll);
printf("Roll is: %d\n",s.roll);
printf("Enter name: ");
scanf("%s",s.name);
printf("Name is: %s\n",s.name);
printf("Enter marks: ");
scanf("%f ",&s.marks);
printf("Marks is: %f",s.marks);
}
Output:-
Enter roll: 4
Roll is: 4
Enter name: Rajdip Pal
Name is: Rajdip
Enter marks: 98
Marks is: 98.000000