0% found this document useful (0 votes)
2 views7 pages

Cp Program 4

cp program

Uploaded by

Sathish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Cp Program 4

cp program

Uploaded by

Sathish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM:

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[100],I,n, temp;
clrscr();
printf(“How many numbers to read? (< 100): “);
scanf(“%d”, &n);
printf(“Enter %d numbers:\n”, n);
for(i=0;i< n;i++)
{
printf(“arr[%d] = “, i);
scanf(“%d”, (arr+i));
}
printf(“\nOriginal array is: \n”);
for(i=0;i< n;i++)
{
printf(“ %d\t”, *(arr+i));
}
for(i=0;i< n/2;i++)
{
temp = *(arr + i);
*(arr + i) = *(arr + n -1 -i);
*(arr + n -1 -i) = temp;
}
printf(“\nReversed array is: \n”);
for(i=0;i< n;i++)
{
printf(“ %d\t”, *(arr+i));
}
getch();
return 0;
}

OUTPUT:
How many numbers to read? (< 100): 5
Enter 5 numbers:
Arr[0] = 1
Arr[1] = 2
Arr[2] = 5
Arr[3] = 4
Arr[4] = 3
Original array is:1 2 3 4 5
Reversed array is:5 4 3 2 1
PROGRAM
#include <stdio.h>
struct Employee
{
char name[50];
int id;
float salary;
};
void addEmployee(struct Employee *emp);
void displayEmployee(struct Employee emp);
int main()
{
struct Employee emp;
addEmployee(&emp);
displayEmployee(emp);
return 0;
}
void addEmployee(struct Employee *emp)
{
printf(“Enter Employee Name: “);
scanf(“%s”, emp->name);
printf(“Enter Employee ID: “);
scanf(“%d”, &emp->id);
printf(“Enter Employee Salary: “);
scanf(“%f”, &emp->salary);
}
void displayEmployee(struct Employee emp)
{
printf(“\nEmployee Details:\n”);
printf(“Name: %s\n”, emp.name);
printf(“ID: %d\n”, emp.id);
printf(“Salary: %.2f\n”, emp.salary);
}
PROGRAM:
#include <stdio.h>
#include <string.h>
struct Department
{
char name[50];
int id;
};
struct Employee
{
char name[50];
int id;
float salary;
struct Department dept;
};
void addEmployee(struct Employee *emp);
void displayEmployee(struct Employee emp);
int main()
struct Employee emp;
addEmployee(&emp);
displayEmployee(emp);
return 0;
}
void addEmployee(struct Employee *emp)
{
printf(“Enter Employee Name: “);
scanf(“%s”, emp->name);
printf(“Enter Employee ID: “);
scanf(“%d”, &emp->id);
printf(“Enter Employee Salary: “);
scanf(“%f”, &emp->salary);
printf(“Enter Department Name: “);
scanf(“%s”, emp->dept.name);
printf(“Enter Department ID: “);
scanf(“%d”, &emp->dept.id);
}
void displayEmployee(struct Employee emp)
{
printf(“\nEmployee Details:\n”);
printf(“Name: %s\n”, emp.name);
printf(“ID: %d\n”, emp.id);
printf(“Salary: %.2f\n”, emp.salary);
printf(“Department Name: %s\n”, emp.dept.name);
printf(“Department ID: %d\n”, emp.dept.id);
}

OUTPUT:
Enter Employee Name: Alice
Enter Employee ID: 101
Enter Employee Salary: 75000
Enter Department Name: IT
Enter Department ID: 5
Employee Details:
Name: Alice
ID: 101
Salary: 75000.00
Department Name: IT
Department ID: 5

You might also like