SlideShare a Scribd company logo
1 of 4
//prepared for Dr. Al-Qadi
//the answer for Q1
#include<stdio.h>
#include<stdlib.h>
int main(){
FILE *in;
int no;
double status;
in=fopen("numbers.txt","r");
if(in==NULL)
exit(1);
status=fscanf(in,"%d",&no);
while(status!=EOF){
if(no%2==0)
printf("The number that exist in file 'numbers.txt' is %dnn",no);
status=fscanf(in,"%d",&no);
}
fclose(in);
system("pause");
return(0);
}
//prepared for Dr. Al-Qadi
//the answer for Q2
#include<stdio.h>
#include<stdlib.h>
void perfect(int no);
int main(){
int no;
printf("Enter a value>");
scanf("%d",&no);
perfect(no);
system("pause");
return(0);
}
void perfect(int no){
int i,sum=0;
for(i=1;i<no;i++){
if(no%i==0)
sum+=i;
}
if(sum==no)
printf("%d is perfectnn",no);
else
printf("%d is not perfectnn",no);
}
//prepared for Dr. Al-Qadi
//the answer for Q3
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void NumTest(int a,int b,int c,double *r1,double *r2);
int main(){
int a,b,c;
double r1,r2;
printf("Enter the values of a,b and c>");
scanf("%d %d %d",&a,&b,&c);
NumTest(a,b,c,&r1,&r2);
printf("r1= %.2f t r2= %.2f nn",r1,r2);
system("pause");
return(0);
}
void NumTest(int a,int b,int c,double *r1,double *r2){
*r1 = (-b + sqrt(b*b - 4*a*c))/ 2.0*a;
*r2 = (-b - sqrt(b*b - 4*a*c))/ 2.0*a;
}
//prepared for Dr. Al-Qadi
//the answer for Q4
#include<stdio.h>
#include<stdlib.h>
double sum(double num1,double num2);
int main(){
double num1, num2, result;
printf("Enter two numbers>");
scanf("%lf %lf",&num1,&num2);
result = sum(num1,num2);
printf("The sum of all numbers in between = %.fnn",result);
system("pause");
return(0);
}
double sum(double num1,double num2){
if(num2-num1==1)
return num1+num2;
else
return num1 + sum(num1+1,num2);
}

More Related Content

What's hot

ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2
drewz lin
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
paulguerin
 

What's hot (19)

ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
week-12x
week-12xweek-12x
week-12x
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
Controlfile
ControlfileControlfile
Controlfile
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Drupal and Open shift (and php)
Drupal and Open shift (and php)Drupal and Open shift (and php)
Drupal and Open shift (and php)
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6
 
Openpear Project の紹介
Openpear Project の紹介Openpear Project の紹介
Openpear Project の紹介
 
Proces
ProcesProces
Proces
 
C++
C++C++
C++
 
Codes
CodesCodes
Codes
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
Reverse123
Reverse123Reverse123
Reverse123
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
C99[2]
C99[2]C99[2]
C99[2]
 

Viewers also liked

Reesbook presentation
Reesbook presentationReesbook presentation
Reesbook presentation
andresipm
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
altwirqi
 
Presentation1
Presentation1Presentation1
Presentation1
f721
 
Designing informationfinalwaugh
Designing informationfinalwaughDesigning informationfinalwaugh
Designing informationfinalwaugh
patricktwaugh
 
50 common-english-phrasal-verbs
50 common-english-phrasal-verbs50 common-english-phrasal-verbs
50 common-english-phrasal-verbs
altwirqi
 
Chapter 1-hr-overview
Chapter 1-hr-overviewChapter 1-hr-overview
Chapter 1-hr-overview
altwirqi
 
01 intro erp using gbi 1.0, stefan weidner, nov 2009
01 intro erp using gbi 1.0, stefan weidner, nov 200901 intro erp using gbi 1.0, stefan weidner, nov 2009
01 intro erp using gbi 1.0, stefan weidner, nov 2009
altwirqi
 
persoonlijke effectiviteit in de installatie branche alg
persoonlijke effectiviteit in de installatie branche algpersoonlijke effectiviteit in de installatie branche alg
persoonlijke effectiviteit in de installatie branche alg
De Zwerm Groep
 
Design portfolio waugh
Design portfolio waughDesign portfolio waugh
Design portfolio waugh
patricktwaugh
 
Brandstorm Creative Group Portfolio
Brandstorm Creative Group PortfolioBrandstorm Creative Group Portfolio
Brandstorm Creative Group Portfolio
andresipm
 

Viewers also liked (19)

Coachi online coachen
Coachi online coachenCoachi online coachen
Coachi online coachen
 
Normal
NormalNormal
Normal
 
Reesbook presentation
Reesbook presentationReesbook presentation
Reesbook presentation
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
Exam1 011
Exam1 011Exam1 011
Exam1 011
 
0104testr
0104testr0104testr
0104testr
 
Presentation1
Presentation1Presentation1
Presentation1
 
Designing informationfinalwaugh
Designing informationfinalwaughDesigning informationfinalwaugh
Designing informationfinalwaugh
 
50 common-english-phrasal-verbs
50 common-english-phrasal-verbs50 common-english-phrasal-verbs
50 common-english-phrasal-verbs
 
Chapter 1-hr-overview
Chapter 1-hr-overviewChapter 1-hr-overview
Chapter 1-hr-overview
 
01 intro erp using gbi 1.0, stefan weidner, nov 2009
01 intro erp using gbi 1.0, stefan weidner, nov 200901 intro erp using gbi 1.0, stefan weidner, nov 2009
01 intro erp using gbi 1.0, stefan weidner, nov 2009
 
Methode GoldenBox
Methode GoldenBoxMethode GoldenBox
Methode GoldenBox
 
persoonlijke effectiviteit in de installatie branche alg
persoonlijke effectiviteit in de installatie branche algpersoonlijke effectiviteit in de installatie branche alg
persoonlijke effectiviteit in de installatie branche alg
 
Design portfolio waugh
Design portfolio waughDesign portfolio waugh
Design portfolio waugh
 
Trimetrix talenten ontwikkling
Trimetrix talenten ontwikklingTrimetrix talenten ontwikkling
Trimetrix talenten ontwikkling
 
CS Unit Project
CS Unit ProjectCS Unit Project
CS Unit Project
 
Design info work
Design info workDesign info work
Design info work
 
Persoonlijke effectiviteit met een focus op houding en gedrag
Persoonlijke effectiviteit met een focus op houding en gedragPersoonlijke effectiviteit met een focus op houding en gedrag
Persoonlijke effectiviteit met een focus op houding en gedrag
 
Brandstorm Creative Group Portfolio
Brandstorm Creative Group PortfolioBrandstorm Creative Group Portfolio
Brandstorm Creative Group Portfolio
 

Similar to Lab test 2

C basics
C basicsC basics
C basics
MSc CST
 
C code#include stdio.hint main(void) {     FILE infp, o.pdf
C code#include stdio.hint main(void) {     FILE infp, o.pdfC code#include stdio.hint main(void) {     FILE infp, o.pdf
C code#include stdio.hint main(void) {     FILE infp, o.pdf
ankitmobileshop235
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
Eli Diaz
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
Eli Diaz
 

Similar to Lab test 2 (20)

Data structures
Data structuresData structures
Data structures
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C basics
C basicsC basics
C basics
 
C Language Lecture 22
C Language Lecture 22C Language Lecture 22
C Language Lecture 22
 
7 functions
7  functions7  functions
7 functions
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C code#include stdio.hint main(void) {     FILE infp, o.pdf
C code#include stdio.hint main(void) {     FILE infp, o.pdfC code#include stdio.hint main(void) {     FILE infp, o.pdf
C code#include stdio.hint main(void) {     FILE infp, o.pdf
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Double linked list
Double linked listDouble linked list
Double linked list
 
C programms
C programmsC programms
C programms
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 
C program
C programC program
C program
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
 
Cquestions
Cquestions Cquestions
Cquestions
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

Lab test 2

  • 1. //prepared for Dr. Al-Qadi //the answer for Q1 #include<stdio.h> #include<stdlib.h> int main(){ FILE *in; int no; double status; in=fopen("numbers.txt","r"); if(in==NULL) exit(1); status=fscanf(in,"%d",&no); while(status!=EOF){ if(no%2==0) printf("The number that exist in file 'numbers.txt' is %dnn",no); status=fscanf(in,"%d",&no); } fclose(in); system("pause"); return(0); }
  • 2. //prepared for Dr. Al-Qadi //the answer for Q2 #include<stdio.h> #include<stdlib.h> void perfect(int no); int main(){ int no; printf("Enter a value>"); scanf("%d",&no); perfect(no); system("pause"); return(0); } void perfect(int no){ int i,sum=0; for(i=1;i<no;i++){ if(no%i==0) sum+=i; } if(sum==no) printf("%d is perfectnn",no); else printf("%d is not perfectnn",no); }
  • 3. //prepared for Dr. Al-Qadi //the answer for Q3 #include<stdio.h> #include<stdlib.h> #include<math.h> void NumTest(int a,int b,int c,double *r1,double *r2); int main(){ int a,b,c; double r1,r2; printf("Enter the values of a,b and c>"); scanf("%d %d %d",&a,&b,&c); NumTest(a,b,c,&r1,&r2); printf("r1= %.2f t r2= %.2f nn",r1,r2); system("pause"); return(0); } void NumTest(int a,int b,int c,double *r1,double *r2){ *r1 = (-b + sqrt(b*b - 4*a*c))/ 2.0*a; *r2 = (-b - sqrt(b*b - 4*a*c))/ 2.0*a; }
  • 4. //prepared for Dr. Al-Qadi //the answer for Q4 #include<stdio.h> #include<stdlib.h> double sum(double num1,double num2); int main(){ double num1, num2, result; printf("Enter two numbers>"); scanf("%lf %lf",&num1,&num2); result = sum(num1,num2); printf("The sum of all numbers in between = %.fnn",result); system("pause"); return(0); } double sum(double num1,double num2){ if(num2-num1==1) return num1+num2; else return num1 + sum(num1+1,num2); }