0% found this document useful (0 votes)
331 views

Adv C Slip 1 Solution

C programming

Uploaded by

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

Adv C Slip 1 Solution

C programming

Uploaded by

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

Advanced c Slip 1

1) Write a program to find maximum of two numbers using macro. (5 marks).

#include<stdio.h>

#include<stdlib.h>

#define max(a,b) ((a)>(b) ? (a) : (b) )

Int main()

int x, y, result;

printf("Enter number 1: ");

scanf("%d", &x);

printf("Enter number 2: ");

scanf("%d", &y);

result = max(x,y);

printf("Maximum of %d and %d is %d \n", x, y, result);

return 0;

2) Write a program to accept to compute sum and average of all elements in an array using pointer.
(10 marks).

#include<stdio.h>

void calsum(int *arr, int size, float *sum, float *average)

*sum=0;

for(int i=0;i<size;i++)

*sum+=*(arr+i);

*average=*sum/size;

int main()

{
int size;

printf("Enter the size of the array: ");

scanf("%d", &size);

int *arr=(int *)malloc(size *sizeof(int));

printf("Enter the elements of the array: \n");

for(int i=0;i<size;i++)

printf("Element %d: ",i+1);

scanf("%d",arr+i);

float sum, average;

calsum(arr, size, &sum, &average);

printf("\n Sum : %f\n", sum);

printf("\n average : %f \n", average);

free(arr);

return 0;

3) Write a program to accept details of n students (roll number, name, percentage) using structure.
Display details of the student having maximum percentage. (15 marks)

#include<stdio.h>

struct student

char name[25];

int roll_no;

float percentage;

};

void main()

int number;

printf("Enter number of students data you want to accept : ");


scanf("%d", &number);

struct student s[number];

int i;

for(i=0;i<number;i++)

printf("Enter number of student %d : \n", i+1);

printf("Enter Roll Number ");

scanf("%d", &s[i].roll_no);

printf("Enter Name ");

scanf("%s", &s[i].name);

printf("Enter Percentage ");

scanf("%f", &s[i].percentage);

//find the students with the maximum percentage

int max=0;

for(i=1;i<number;i++)

if(s[i].percentage > s[max].percentage)

max=i;

printf("\n Details of the student with the maximum percentage: \n");

printf(" Roll Number : %d\n", s[max].roll_no);

printf(" Name : %s\n",s[max].name);

printf("Percentage : %f\n", s[max].percentage);

return 0;
}

You might also like