Cycle 3 Programs
Cycle 3 Programs
1. Write a C program using structure to read and display details of ‘n’ employees.
Program
#include <stdio.h>
/*structure declaration*/ Output
struct employee{
Enter details :
char name[30];
Name ?:Mike
int empId;
float salary; ID ?:1120
}; Salary ?:76543
void main()
{
Entered detail is:
/*declare structure variable*/
struct employee emp; Name: Mike
Id: 1120
/*read employee details*/
Salary: 76543.000000
printf("\nEnter details :\n");
printf("Name ?:"); gets(emp.name);
printf("ID ?:"); scanf("%d",&emp.empId);
printf("Salary ?:"); scanf("%f",&emp.salary);
#include <stdio.h>
void main()
{
int num=123; Output
int *p1; Value of num is: 123
int **p2;
p1 = # Value of num using p1 is: 123
p2 = &p1;
Value of num using p2 is: 123
printf("\n Value of num is: %d", num);
printf("\n Value of num using p1 is: %d", *p1); Address of num is: ff114466
printf("\n Value of num using p2 is: %d", **p2);
printf("\n Address of num is: %p", &num); Address of num using p1 is: ff114466
printf("\n Address of num using p1 is: %p", p1);
Address of num using p2 is: ff114466
printf("\n Address of num using p2 is: %p", *p2);
printf("\n Value of Pointer p1 is: %p", p1);
printf("\n Value of Pointer p1 using p2 is: %p", *p2);
printf("\n Address of Pointer p1 is:%p",&p1);
printf("\n Address of Pointer p1 using p2 is:%p",p2);
printf("\n Value of Pointer p2 is:%p",p2);
printf("\n Address of Pointer p2 is:%p",&p2);
}
// Open file
fptr = fopen(filename, "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
exit(0);
}
// Read contents from file
c = fgetc(fptr);
while (c != EOF)
{
printf ("%c", c);
c = fgetc(fptr);
}
fclose(fptr);
return 0;
}
personal_details()
7. Write a python program to print factors of a number using function
Program
Output
print_factors(num) 10
16
20
32
40
64
80
160
320