SlideShare una empresa de Scribd logo
1 de 4
/* 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);

}

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Destacado (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 a week-23x

Similar a 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
 

Más de 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
 

Último

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

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