SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
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;
}

Más contenido relacionado

La actualidad más candente

Program transpose matriks
Program transpose matriksProgram transpose matriks
Program transpose matriksSimon Patabang
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C LabNeil Mathew
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfCS With Logic
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassYogendra Rampuria
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And AnswersH2Kinfosys
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarSivakumar R D .
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Alamgir Hossain
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 

La actualidad más candente (20)

Class or Object
Class or ObjectClass or Object
Class or Object
 
Program transpose matriks
Program transpose matriksProgram transpose matriks
Program transpose matriks
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of Class
 
Strings in c
Strings in cStrings in c
Strings in c
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Data types
Data typesData types
Data types
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
C++ references
C++ referencesC++ references
C++ references
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Variables and Data Types
Variables and Data TypesVariables and Data Types
Variables and Data Types
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 

Similar a C- Programming Assignment 4 solution

Similar a C- Programming Assignment 4 solution (20)

Unit2 C
Unit2 C Unit2 C
Unit2 C
 
Unit2 C
Unit2 CUnit2 C
Unit2 C
 
C programs
C programsC programs
C programs
 
C-programs
C-programsC-programs
C-programs
 
week-3x
week-3xweek-3x
week-3x
 
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...
 
C programs
C programsC programs
C programs
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Najmul
Najmul  Najmul
Najmul
 
C file
C fileC file
C file
 
7 functions
7  functions7  functions
7 functions
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Input output functions
Input output functionsInput output functions
Input output functions
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
chapter-6 slide.pptx
chapter-6 slide.pptxchapter-6 slide.pptx
chapter-6 slide.pptx
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
A10presentationofbiologyandpshyology.pptx
A10presentationofbiologyandpshyology.pptxA10presentationofbiologyandpshyology.pptx
A10presentationofbiologyandpshyology.pptx
 

Más de Animesh Chaturvedi

Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworksAnimesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle managementAnimesh 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 answersAnimesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering TopicsAnimesh 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-HardAnimesh 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 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineeringAnimesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems EngineeringAnimesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingAnimesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and FrameworksAnimesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle ManagementAnimesh 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 expressionAnimesh Chaturvedi
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machineAnimesh Chaturvedi
 

Más de Animesh Chaturvedi (20)

Cloud Platforms & Frameworks
Cloud Platforms & FrameworksCloud Platforms & Frameworks
Cloud Platforms & Frameworks
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
 
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
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
 
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
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
 
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...
 
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...
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
 
Informatics systems
Informatics systemsInformatics systems
Informatics systems
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
 
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?
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
Pattern detection in mealy machine
Pattern detection in mealy machinePattern detection in mealy machine
Pattern detection in mealy machine
 

Último

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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; }