SlideShare a Scribd company logo
Lab Assignment 4: Function and Pointer in C Programming
CS-153 Computer Programming Lab
Autumn Semester, 2016, IIT Indore
Date: 26-08-16
Note: Write following programs in C language. Also note that this assignment will be evaluated by
TA’s in the upcoming labs of next week (29-08-16 onward) for each batch.
1. Write a program to calculate area and perimeter of a circle by using two different functions. Both the
functions take radius as pass by value. Area function will return area. Perimeter function will return
perimeter.
2. Write a static memory program for 4 students with 3 subjects. Compute the total for each student and
store it into array. Input will be taken through a function. Marks calculation will be done through a
separated function.
3. Compute Fibonacci(N) for given N using recursion. Print how many calls are required for obtaining
this Nth
number in the series?
4. a. Write a program to print address and value of variable.
b. Write a program to print array values and address of an array using pointers.
5. Write a dynamic memory program for N students with M subjects. Compute the total for each student
and store it into array. Input will be taken through a function. Marks calculation will be done through
a separated function.
6. Create a structure to specify data of students given below:
Roll number, Name, Department, Course, Year of joining
Assume that there are varying numbers of students in the institute.
(a) Write a function to print names of all students who joined in a particular year.
(b) Write a function to print the data of a student whose roll number is given.
#include <stdio.h>
const float PI = 3.1415927;
float area(float radius);
float circum(float radius);
#include<stdio.h>
main()
{
float radius;
printf("Enter radius: ");
scanf("%f", &radius);
printf("Area : %.3fn", area(radius));
printf("Circumference: %.3fn", circum(radius));
getch();
}
/* return area of a circle */
float area(float radius)
{
return PI * radius * radius;
}
/* return circumference of a circle */
float circum(float radius)
{
return 2 * PI * radius;
}
#include<stdio.h>
#define SIZE 4
struct student {
char name[30];
int rollno;
int sub[3];
};
main() {
int i, j, max, count, total, n, a[SIZE], ni;
struct student st[SIZE];
printf("Enter how many students: ");
scanf("%d", &n);
/* for loop to read the names and roll numbers*/
for (i = 0; i < n; i++) {
printf("nEnter name and roll number for student %d : ", i);
scanf("%s", &st[i].name);
scanf("%d", &st[i].rollno);
}
/* for loop to read ith student's jth subject*/
for (i = 0; i < n; i++) {
for (j = 0; j <= 2; j++) {
printf("nEnter marks of student %d for subject %d : ", i, j);
scanf("%d", &st[i].sub[j]);
}
}
/* (i) for loop to calculate total marks obtained by each student*/
for (i = 0; i < n; i++) {
total = 0;
for (j = 0; j < 3; j++) {
total = total + st[i].sub[j];
}
printf("nTotal marks obtained by student %s are %dn", st[i].name,total);
a[i] = total;
}
getch();
}
#include<stdio.h>
int Fibonacci(int); //function declared
int count = 0; //global variable
int main()
{
int n, i = 0, c;
printf("Enter the length of the series or number of terms for Fibonacci Seriesn");
scanf("%d",&n);
printf("Fibonacci series:n");
for ( c = 1 ; c <=n ; c++ )
{
printf("%dn", Fibonacci(i)); //function called once
i++;
}
printf("Function called count -> %d",count);
return 0;
}
int Fibonacci(int n) //function defined
{
count++;
if ( n == 0 )
{
return 0;
}
else if ( n == 1 )
{
return 1;
}
else
{
return ( Fibonacci(n-1) + Fibonacci(n-2) ); //function called twice
}
}
#include <stdio.h>
main()
{
char a;
int x;
float p, q;
a = 'A';
x = 125;
p = 10.25, q = 18.76;
printf("%c is stored at addr %u.n", a, &a);
printf("%d is stored at addr %u.n", x, &x);
printf("%f is stored at addr %u.n", p, &p);
printf("%f is stored at addr %u.n", q, &q);
getch();
}
#include <stdio.h>
main()
{
int a[5];int i;
for(i = 0; i<=5; i++)
{
a[i]=i;
}
printdetail(a);
printarr(a);
getch();
}
printarr(int a[])
{ int i;
for(i = 0;i<=5;i++)
{
printf("value in array %dn",a[i]);
}
}
printdetail(int a[])
{int i;
for(i = 0;i<=5;i++)
{
printf("value in array %d and address is %8un",a[i],&a[i]);
}
}
# include <string.h>
# include <stdio.h>
struct student
{
char name[10];
int m[3];
int total;
}*p,*s;
main()
{
int i,j,l,n;
printf("Enter the no. of students : ");
scanf("%d",&n);
p=(struct student*)malloc(n*sizeof(struct student));
s=p;
for(i=0;i<n;i++)
{
printf("Enter a name : ");
scanf("%s",&p->name);
p-> total=0;l=0;
for(j=0;j<3;j++)
{
one:printf("Enter Marks of %d Subject : ",j+1);
scanf("%d",&p->m[j]);
if((p->m[j])>100)
{
printf("Wrong Value Entered");
goto one;
}
p->total+=p->m[j];
}
}
for(i=0;i<n;i++)
{
printf("n%st%d",s->name,s->total);
s++;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#define N 5
struct students {
int rlnm;
char name[25];
char dept[25]; /* structure defined outside of main(); */
char course[25];
int year;
};
main() {
/* main() */
struct students s[N];
int i, ch;
/* taking input of 450 students in an array of structure */
for (i = 0; i < N; i++) {
printf(" Enter data of student %dtttttotal students: %dn", i +
1, N);
printf("****************************nn");
printf("enter rollnumber: ");
scanf("%d", & s[i].rlnm);
printf("nnenter name: ");
scanf(" %s", & s[i].name);
printf("nnenter department: ");
scanf("%s", & s[i].dept);
printf("nnenter course: ");
scanf("%s", & s[i].course);
printf("nnenter year of joining: ");
scanf("%d", & s[i].year);
}
/* displaying a menu */
printf("ntenter your choice: n");
printf("t**********************nn");
printf("1: enter year to search all students who took admission in
that:nn");
printf("2: enter roll number to see details of that studentnnn");
printf("your choice: ");
/* taking input of your choice */
scanf("%d", & ch);
switch (ch) {
case 1:
dispyr( & s);
/* function call to display names of students who joined in
a particular year */
break;
case 2:
disprl( & s);
/* function call to display information of a student 
whose roll number is given */
break;
default:
printf("nnerror! wrong choice");
}
getch();
}
/**
* ***************** main() ends *************
*/
dispyr(struct students *a) { /* function for displaying names of students
who took admission in a particular year */
int j, yr;
printf("nenter year: ");
scanf("%d", & yr);
printf("nnthese students joined in %dnn", yr);
for (j = 0; j < N; j++) {
if (a[j].year == yr) {
printf("n%sn", a[j].name);
}
}
return 0;
}
disprl(struct students *a) { /* function to print information of a
student whose roll number has been 
given. */
int k, rl;
printf("nenter roll number: ");
scanf("%d", & rl);
for (k = 0; k < N; k++) {
if (a[k].rlnm == rl) {
printf("nnt Details of roll number: %dn", a[k].rlnm);
printf("t***************************nn");
printf(" Name: %sn", a[k].name);
printf(" Department: %sn", a[k].dept);
printf(" Course: %sn", a[k].course);
printf("Year of joining: %d", a[k].year);
break;
} else {
printf("nRoll number you entered does not existnn");
break;
}
}
return 0;
}
Ad

More Related Content

What's hot (20)

Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
Muhammad Hammad Waseem
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
Masudul Haque
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
Animesh Chaturvedi
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Programming in C
Programming in CProgramming in C
Programming in C
Rvishnupriya2
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
Hitesh Patel
 
Concept of file handling in c
Concept of file handling in cConcept of file handling in c
Concept of file handling in c
MugdhaSharma11
 
Null / Not Null value
Null / Not Null valueNull / Not Null value
Null / Not Null value
Dhirendra Chauhan
 
Storage classes
Storage classesStorage classes
Storage classes
Leela Koneru
 
1 q on operators
1 q on operators1 q on operators
1 q on operators
ABHIJEET KHIRE
 
Input and Output
Input and OutputInput and Output
Input and Output
Jason J Pulikkottil
 
Ch-12-Strings.ppt.pptx
Ch-12-Strings.ppt.pptxCh-12-Strings.ppt.pptx
Ch-12-Strings.ppt.pptx
ssuser3ae29f
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Kathirvel Ayyaswamy
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
Kavindu Sachinthe
 
Arrays In C
Arrays In CArrays In C
Arrays In C
yndaravind
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
Rajendran
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
Muthuganesh S
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
Muhammad Hammad Waseem
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
Masudul Haque
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
Hitesh Patel
 
Concept of file handling in c
Concept of file handling in cConcept of file handling in c
Concept of file handling in c
MugdhaSharma11
 
Ch-12-Strings.ppt.pptx
Ch-12-Strings.ppt.pptxCh-12-Strings.ppt.pptx
Ch-12-Strings.ppt.pptx
ssuser3ae29f
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
Muthuganesh S
 

Similar to C- Programming Assignment 4 solution (20)

Unit2 C
Unit2 C Unit2 C
Unit2 C
arnold 7490
 
Unit2 C
Unit2 CUnit2 C
Unit2 C
arnold 7490
 
C programs
C programsC programs
C programs
Vikram Nandini
 
C-programs
C-programsC-programs
C-programs
SSGMCE SHEGAON
 
week-3x
week-3xweek-3x
week-3x
KITE www.kitecolleges.com
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
kushwahashivam413
 
C programs
C programsC programs
C programs
Bharathi N Reddy
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
Najmul
Najmul  Najmul
Najmul
Najmul Ashik
 
C file
C fileC file
C file
simarsimmygrewal
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
Computer P-Lab-Manual acc to syllabus.pdf
Computer P-Lab-Manual acc to syllabus.pdfComputer P-Lab-Manual acc to syllabus.pdf
Computer P-Lab-Manual acc to syllabus.pdf
sujathachoudaryn29
 
Input output functions
Input output functionsInput output functions
Input output functions
hyderali123
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
Principals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdfPrincipals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
chapter-6 slide.pptx
chapter-6 slide.pptxchapter-6 slide.pptx
chapter-6 slide.pptx
cricketreview
 
Ad

More from Animesh Chaturvedi (20)

Cloud Platforms & Frameworks
Cloud Platforms & FrameworksCloud Platforms & Frameworks
Cloud Platforms & Frameworks
Animesh Chaturvedi
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
Animesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
Animesh Chaturvedi
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
Animesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
Animesh Chaturvedi
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
Animesh Chaturvedi
 
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Animesh Chaturvedi
 
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Animesh Chaturvedi
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
Animesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
Animesh Chaturvedi
 
Informatics systems
Informatics systemsInformatics systems
Informatics systems
Animesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
Animesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
Animesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
Animesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
Animesh Chaturvedi
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
Animesh Chaturvedi
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
Animesh Chaturvedi
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machine
Animesh Chaturvedi
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
Animesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
Animesh Chaturvedi
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
Animesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
Animesh Chaturvedi
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
Animesh Chaturvedi
 
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Animesh Chaturvedi
 
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Animesh Chaturvedi
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
Animesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
Animesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
Animesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
Animesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
Animesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
Animesh Chaturvedi
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
Animesh Chaturvedi
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
Animesh Chaturvedi
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machine
Animesh Chaturvedi
 
Ad

Recently uploaded (20)

Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 

C- Programming Assignment 4 solution

  • 1. Lab Assignment 4: Function and Pointer in C Programming CS-153 Computer Programming Lab Autumn Semester, 2016, IIT Indore Date: 26-08-16 Note: Write following programs in C language. Also note that this assignment will be evaluated by TA’s in the upcoming labs of next week (29-08-16 onward) for each batch. 1. Write a program to calculate area and perimeter of a circle by using two different functions. Both the functions take radius as pass by value. Area function will return area. Perimeter function will return perimeter. 2. Write a static memory program for 4 students with 3 subjects. Compute the total for each student and store it into array. Input will be taken through a function. Marks calculation will be done through a separated function. 3. Compute Fibonacci(N) for given N using recursion. Print how many calls are required for obtaining this Nth number in the series? 4. a. Write a program to print address and value of variable. b. Write a program to print array values and address of an array using pointers. 5. Write a dynamic memory program for N students with M subjects. Compute the total for each student and store it into array. Input will be taken through a function. Marks calculation will be done through a separated function. 6. Create a structure to specify data of students given below: Roll number, Name, Department, Course, Year of joining Assume that there are varying numbers of students in the institute. (a) Write a function to print names of all students who joined in a particular year. (b) Write a function to print the data of a student whose roll number is given.
  • 2. #include <stdio.h> const float PI = 3.1415927; float area(float radius); float circum(float radius); #include<stdio.h> main() { float radius; printf("Enter radius: "); scanf("%f", &radius); printf("Area : %.3fn", area(radius)); printf("Circumference: %.3fn", circum(radius)); getch(); } /* return area of a circle */ float area(float radius) { return PI * radius * radius; } /* return circumference of a circle */ float circum(float radius) { return 2 * PI * radius; }
  • 3. #include<stdio.h> #define SIZE 4 struct student { char name[30]; int rollno; int sub[3]; }; main() { int i, j, max, count, total, n, a[SIZE], ni; struct student st[SIZE]; printf("Enter how many students: "); scanf("%d", &n); /* for loop to read the names and roll numbers*/ for (i = 0; i < n; i++) { printf("nEnter name and roll number for student %d : ", i); scanf("%s", &st[i].name); scanf("%d", &st[i].rollno); } /* for loop to read ith student's jth subject*/ for (i = 0; i < n; i++) { for (j = 0; j <= 2; j++) { printf("nEnter marks of student %d for subject %d : ", i, j); scanf("%d", &st[i].sub[j]); } } /* (i) for loop to calculate total marks obtained by each student*/ for (i = 0; i < n; i++) { total = 0; for (j = 0; j < 3; j++) { total = total + st[i].sub[j]; } printf("nTotal marks obtained by student %s are %dn", st[i].name,total); a[i] = total; } getch(); }
  • 4. #include<stdio.h> int Fibonacci(int); //function declared int count = 0; //global variable int main() { int n, i = 0, c; printf("Enter the length of the series or number of terms for Fibonacci Seriesn"); scanf("%d",&n); printf("Fibonacci series:n"); for ( c = 1 ; c <=n ; c++ ) { printf("%dn", Fibonacci(i)); //function called once i++; } printf("Function called count -> %d",count); return 0; } int Fibonacci(int n) //function defined { count++; if ( n == 0 ) { return 0; } else if ( n == 1 ) { return 1; } else { return ( Fibonacci(n-1) + Fibonacci(n-2) ); //function called twice } }
  • 5. #include <stdio.h> main() { char a; int x; float p, q; a = 'A'; x = 125; p = 10.25, q = 18.76; printf("%c is stored at addr %u.n", a, &a); printf("%d is stored at addr %u.n", x, &x); printf("%f is stored at addr %u.n", p, &p); printf("%f is stored at addr %u.n", q, &q); getch(); }
  • 6. #include <stdio.h> main() { int a[5];int i; for(i = 0; i<=5; i++) { a[i]=i; } printdetail(a); printarr(a); getch(); } printarr(int a[]) { int i; for(i = 0;i<=5;i++) { printf("value in array %dn",a[i]); } } printdetail(int a[]) {int i; for(i = 0;i<=5;i++) { printf("value in array %d and address is %8un",a[i],&a[i]); } }
  • 7. # include <string.h> # include <stdio.h> struct student { char name[10]; int m[3]; int total; }*p,*s; main() { int i,j,l,n; printf("Enter the no. of students : "); scanf("%d",&n); p=(struct student*)malloc(n*sizeof(struct student)); s=p; for(i=0;i<n;i++) { printf("Enter a name : "); scanf("%s",&p->name); p-> total=0;l=0; for(j=0;j<3;j++) { one:printf("Enter Marks of %d Subject : ",j+1); scanf("%d",&p->m[j]); if((p->m[j])>100) { printf("Wrong Value Entered"); goto one; } p->total+=p->m[j]; } } for(i=0;i<n;i++) { printf("n%st%d",s->name,s->total); s++; } getch(); }
  • 8. #include<stdio.h> #include<conio.h> #define N 5 struct students { int rlnm; char name[25]; char dept[25]; /* structure defined outside of main(); */ char course[25]; int year; }; main() { /* main() */ struct students s[N]; int i, ch; /* taking input of 450 students in an array of structure */ for (i = 0; i < N; i++) { printf(" Enter data of student %dtttttotal students: %dn", i + 1, N); printf("****************************nn"); printf("enter rollnumber: "); scanf("%d", & s[i].rlnm); printf("nnenter name: "); scanf(" %s", & s[i].name); printf("nnenter department: "); scanf("%s", & s[i].dept); printf("nnenter course: "); scanf("%s", & s[i].course); printf("nnenter year of joining: "); scanf("%d", & s[i].year); } /* displaying a menu */ printf("ntenter your choice: n"); printf("t**********************nn"); printf("1: enter year to search all students who took admission in that:nn"); printf("2: enter roll number to see details of that studentnnn"); printf("your choice: "); /* taking input of your choice */ scanf("%d", & ch); switch (ch) { case 1: dispyr( & s); /* function call to display names of students who joined in a particular year */ break; case 2:
  • 9. disprl( & s); /* function call to display information of a student whose roll number is given */ break; default: printf("nnerror! wrong choice"); } getch(); } /** * ***************** main() ends ************* */ dispyr(struct students *a) { /* function for displaying names of students who took admission in a particular year */ int j, yr; printf("nenter year: "); scanf("%d", & yr); printf("nnthese students joined in %dnn", yr); for (j = 0; j < N; j++) { if (a[j].year == yr) { printf("n%sn", a[j].name); } } return 0; } disprl(struct students *a) { /* function to print information of a student whose roll number has been given. */ int k, rl; printf("nenter roll number: "); scanf("%d", & rl); for (k = 0; k < N; k++) { if (a[k].rlnm == rl) { printf("nnt Details of roll number: %dn", a[k].rlnm); printf("t***************************nn"); printf(" Name: %sn", a[k].name); printf(" Department: %sn", a[k].dept); printf(" Course: %sn", a[k].course); printf("Year of joining: %d", a[k].year); break; } else {
  • 10. printf("nRoll number you entered does not existnn"); break; } } return 0; }
  翻译: