Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ansh singhal jeg221693

week 12 a

Ans 1.)
#include<stdio.h> struct
student{
char
name[20];
int number;
int rank;
}s1;
int main(){
printf("Enter the details of student:\n");
printf("Enter the name of student:");
gets(s1.name);
printf("Enter the roll number of the
student:"); scanf("%d",&s1.number);
printf("Enter the rank of the student:");
scanf("%d",&s1.rank);
struct student *ptr = &s1; printf("\
nCandidate name:%s\n",ptr->name);
printf("Roll number:%d\n",ptr->number);
printf("Rank is:%d",ptr->rank);
return 0;
}

Ans2.)
#include<stdi.h> int
comp(int a, int b);
int
main
()
{ int
n,m;
printf("Enter the first number:");
scanf("%d",&n);
printf("Enter the second number:");
scanf("%d",&m);
comp(n,m);
return 0;
}
int comp(int a,int b){
if(a>=b){
int *ptr=&a;
printf("The value of the greater number is:%d\n", *ptr);
printf("The address of the greater number is:%d", ptr);
}
else{
int *ptr=&b;
printf("The value of the greater number is:%d\n", *ptr);
printf("The address of the greater number is:%d", ptr);
}
}

Ans 3.) #include<stdio.h>


int main(){
int n;
printf("Enter the number of elements in array:");
scanf("%d",&n);
int arr[n];
printf("Enter the elements of array:");
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
int *ptr=arr;
int t;
for(int i=0;i<n;i++){
for(int j=0;j<n-1-i;j++){
if(*(ptr+j+1)<*(ptr+j)){
t=*(ptr+j+1);
*(ptr+j+1)=*(ptr+j);
*(ptr+j)=t;
}
}
}
printf("The sorted array is:");
for(int i=0;i<n;i++){
printf("%d\n",*(ptr+i));
}
return 0;
}

Ans 4.) #include<stdio.h>


struct names{
char strings[30];
}arr[6];
int main(){
for(int i=0;i<6;i++){
printf("Enter the string%d:",i+1);
scanf("%s",arr[i].strings);
}
struct names *ptr = &arr;
for(int i=0;i<6;i++){
printf("\nString%d is:%s\n",i+1,(ptr+i)->strings);
printf("\tAddress of string%d is:%u",i+1,(ptr+i)->strings);
}
return 0;
}

You might also like