SlideShare a Scribd company logo
/* Write C program to implement the linear regression algorithm. */



#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<string.h>



float mean(float *a, int n);

void deviation(float *a, float mean, int n, float *d, float *S);



void main()

{

    float a[20],b[20],dx[20],dy[20];

    float sy=0,sx=0,mean_x=0,mean_y=0,sum_xy=0;

    float corr_coff=0,reg_coff_xy=0, reg_coff_yx=0;

    char type_coff[7];

    int n=0,i=0;



    clrscr();



    printf("Enter the value of n: ");

    scanf("%d",&n);

    printf("Enter the values of x and y:n");

    for(i=0;i<n;i++)
scanf("%f%f",&a[i],&b[i]);

mean_x=mean(a,n);

mean_y=mean(b,n);

deviation(a,mean_x,n,dx,&sx);

deviation(b,mean_y,n,dy,&sy);



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

    sum_xy=sum_xy+dx[i]*dy[i];

corr_coff=sum_xy/(n*sx*sy);

printf("Enter the type of regression coefficient as 'x on y' or 'y on x': ");

fflush(stdin);

gets(type_coff);



if(strcmp(type_coff,"x on y")==1)

{

        reg_coff_xy=corr_coff*(sx/sy);

        printf("nThe value of linear regression coefficient is %f",reg_coff_xy);

}

else if(strcmp(type_coff,"y on x")==1)

{

        reg_coff_yx=corr_coff*(sy/sx);

        printf("nThe value of linear regression coefficient is %f",reg_coff_yx);

}

else
printf("nEnter the correct type of regression coefficient.");

    getch();

}




float mean(float *a, int n)

{

    float sum=0, i=0;

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

        sum=sum+a[i];

    sum=sum/n;

    return (sum);

}



void deviation(float *a, float mean, int n, float *d, float *s)

{

    float sum=0,t=0;

    int i=0;

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

    {

        d[i]=a[i]-mean;

        t=d[i]*d[i];

        sum=sum+t;

    }
sum=sum/n;

    *s=sqrt(sum);

}

More Related Content

What's hot

Computer programing w
Computer programing wComputer programing w
Computer programing w
cexpertise
 
Metnum
MetnumMetnum
Metnum
ratnaaning
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
9096308941
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
Tanya Makkar
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
Hanokh Aloni
 
Project filter matlab
Project  filter matlabProject  filter matlab
Project filter matlab
girma disasa
 
Odd number
Odd numberOdd number
Odd number
Ankit Dubey
 
Switch
SwitchSwitch
Switch
Ankit Dubey
 
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3
Dr. Loganathan R
 
Euler method in c
Euler method in cEuler method in c
Euler method in c
Subir Halder
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
Dr. Loganathan R
 
Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
mohdshanu
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
Dr. Loganathan R
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
Dr. Loganathan R
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
University of Potsdam
 

What's hot (20)

week-5x
week-5xweek-5x
week-5x
 
week-11x
week-11xweek-11x
week-11x
 
week-1x
week-1xweek-1x
week-1x
 
Computer programing w
Computer programing wComputer programing w
Computer programing w
 
Metnum
MetnumMetnum
Metnum
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
 
Project filter matlab
Project  filter matlabProject  filter matlab
Project filter matlab
 
Odd number
Odd numberOdd number
Odd number
 
Switch
SwitchSwitch
Switch
 
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3
 
Euler method in c
Euler method in cEuler method in c
Euler method in c
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
 
Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
week-4x
week-4xweek-4x
week-4x
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 

Viewers also liked

Javascript Debugging
Javascript DebuggingJavascript Debugging
Javascript Debugging
Jim Gourgoutis
 
Søknadstyper 2011
Søknadstyper 2011Søknadstyper 2011
Energy risk_nov2010
Energy risk_nov2010Energy risk_nov2010
Energy risk_nov2010VU Connected
 

Viewers also liked (11)

ch6
ch6ch6
ch6
 
QT085.Doc
QT085.DocQT085.Doc
QT085.Doc
 
Javascript Debugging
Javascript DebuggingJavascript Debugging
Javascript Debugging
 
Imagen
ImagenImagen
Imagen
 
Søknadstyper 2011
Søknadstyper 2011Søknadstyper 2011
Søknadstyper 2011
 
Intro to Web Sockets
Intro to Web Sockets Intro to Web Sockets
Intro to Web Sockets
 
Energy risk_nov2010
Energy risk_nov2010Energy risk_nov2010
Energy risk_nov2010
 
ch14
ch14ch14
ch14
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 

Similar to week-23x

Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Cpds lab
Cpds labCpds lab
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
C basics
C basicsC basics
C basicsMSc CST
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfilesmrecedu
 
C-Language Unit-2
C-Language Unit-2C-Language Unit-2
C-Language Unit-2
kasaragadda srinivasrao
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
Koshy Geoji
 
C Language code
C Language codeC Language code
C Language code
HafizRashidJaMali
 
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
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
yap_raiza
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
Shahzaib Ajmal
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 

Similar to week-23x (20)

C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Struct examples
Struct examplesStruct examples
Struct examples
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C basics
C basicsC basics
C basics
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
week-22x
week-22xweek-22x
week-22x
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfiles
 
C-Language Unit-2
C-Language Unit-2C-Language Unit-2
C-Language Unit-2
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
C Language code
C Language codeC Language code
C Language code
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 

More from KITE www.kitecolleges.com (18)

ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-16x
week-16xweek-16x
week-16x
 
week-6x
week-6xweek-6x
week-6x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-2x
week-2xweek-2x
week-2x
 
ch3
ch3ch3
ch3
 
Entity Classes and Attributes
Entity Classes and AttributesEntity Classes and Attributes
Entity Classes and Attributes
 
week-20x
week-20xweek-20x
week-20x
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 

week-23x

  • 1. /* Write C program to implement the linear regression algorithm. */ #include<stdio.h> #include<conio.h> #include<math.h> #include<string.h> float mean(float *a, int n); void deviation(float *a, float mean, int n, float *d, float *S); void main() { float a[20],b[20],dx[20],dy[20]; float sy=0,sx=0,mean_x=0,mean_y=0,sum_xy=0; float corr_coff=0,reg_coff_xy=0, reg_coff_yx=0; char type_coff[7]; int n=0,i=0; clrscr(); printf("Enter the value of n: "); scanf("%d",&n); printf("Enter the values of x and y:n"); for(i=0;i<n;i++)
  • 2. scanf("%f%f",&a[i],&b[i]); mean_x=mean(a,n); mean_y=mean(b,n); deviation(a,mean_x,n,dx,&sx); deviation(b,mean_y,n,dy,&sy); for(i=0;i<n;i++) sum_xy=sum_xy+dx[i]*dy[i]; corr_coff=sum_xy/(n*sx*sy); printf("Enter the type of regression coefficient as 'x on y' or 'y on x': "); fflush(stdin); gets(type_coff); if(strcmp(type_coff,"x on y")==1) { reg_coff_xy=corr_coff*(sx/sy); printf("nThe value of linear regression coefficient is %f",reg_coff_xy); } else if(strcmp(type_coff,"y on x")==1) { reg_coff_yx=corr_coff*(sy/sx); printf("nThe value of linear regression coefficient is %f",reg_coff_yx); } else
  • 3. printf("nEnter the correct type of regression coefficient."); getch(); } float mean(float *a, int n) { float sum=0, i=0; for(i=0;i<n;i++) sum=sum+a[i]; sum=sum/n; return (sum); } void deviation(float *a, float mean, int n, float *d, float *s) { float sum=0,t=0; int i=0; for(i=0;i<n;i++) { d[i]=a[i]-mean; t=d[i]*d[i]; sum=sum+t; }
  • 4. sum=sum/n; *s=sqrt(sum); }