Professional Documents
Culture Documents
2023 - Lab Sheet #6 - ECEN1012
2023 - Lab Sheet #6 - ECEN1012
2023 - Lab Sheet #6 - ECEN1012
LAB #6
NAME:____________________
STUDENT ID:____________________
MARK:____________________
Note: If any kind of plagiarism is found, the involved students will receive zero marks for
this assignment.
Question 6-1: Please compile and execute the following C program, understand the output, then copy
and paste the output.
Code:
#include <stdio.h>
int main(void)
{
int i=5, m=300;
float fx = 300.60;
char cht = 'z';
int *pt1, *p;
float *pt2;
char *pt3;
p=&i;
pt1= &m;
pt2=&fx;
pt3=&cht;
printf("%d\n %d\n %d\n %d\n", *p+2, **&p, 3**p, **&p+4);
printf ( " m = %d\n",m);
printf ( " fx = %f\n",fx);
printf ( " cht = %c\n",cht);
printf("-----------------------\n");
printf ( " address of m = %p\n",&m);
printf ( " address of fx = %p\n",&fx);
printf ( " address of cht = %p\n",&cht);
printf("-----------------------------\n");
printf ( " value at address of m = %d\n",*(&m));
printf ( " value at address of fx = %f\n",*(&fx));
printf ( " value at address of cht = %c\n",*(&cht));
printf("----------------------------------\n");
printf ( " address of m = %p\n",pt1);
printf ( " address of fx = %p\n",pt2);
printf ( " address of cht = %p\n",pt3);
printf("----------------------------------\n");
printf ( " value at address of m = %d\n",*pt1);
printf ( " value at address of fx= %f\n",*pt2);
printf ( " value at address of cht= %c\n\n",*pt3);
system("pause");
return(0);
}
Code
#include <stdio.h>
void swapNumbers(int *x,int *y,int *z);
int main()
{
int e1,e2,e3;
printf(" Input the value of 1st element : ");
scanf("%d",&e1);
printf(" Input the value of 2nd element : ");
scanf("%d",&e2);
printf(" Input the value of 3rd element : ");
scanf("%d",&e3);
printf("\n The value before swapping are :\n");
printf(" element 1 = %d\n element 2 = %d\n element 3 = %d\n",e1,e2,e3);
swapNumbers(&e1,&e2,&e3);
printf("\n The value after swapping are :\n");
printf(" element 1 = %d\n element 2 = %d\n element 3 = %d\n\n",e1,e2,e3);
return 0;
}
Void swapnumbers(int *a,int *b, int *c);
{int *a, *b, *c, unio;
Unio=a;
A=c;
C=unio;)
Please complete the code for function swapNumbers
Question 6-3: Please write a C program to add two number using pointers. For example, when the
input from the keyboard are 5 and 6, the output of the program is given as follows:
Code:
#include <stdio.h>
Int swap(int *a,int *b)
void main()
{
int fno, sno, *ptr, *qtr, sum;
printf("Input the first number: \n",n);
scanf("%d", &fno);
printf("Input the second number: \n",n);
scanf("%d", &sno);
swap
system("pause");
return(0);
}
Please copy and paste the output:
Question 6-4: Please write a C program to find the factorial of a given number using pointers, where the
number is input from the keyboard.
Code: