SlideShare a Scribd company logo
1 of 50
C-Programming
 C program is made of basic elements, such as
expressions, statements, statement blocks, and function
blocks.
 Constant is a value that never changes
 Variables can be used to present different values
 Expression: is a combination of constants, variables,
and operators that are used to denote computations.
 6 An expression of a constant.
 i An expression of a variable.
 6 + i An expression of a constant plus a variable.
 exit(0) An expression of a function call.
 Arithmetic Operators
 + Addition
 - Subtraction
 * Multiplication
 / Division
 % Remainder (or modulus)(6%4=2)
 Note:
 2 + 3 * 10
 (2+ (3 * 10))
 statement is a complete instruction, ending
with a semicolon.
 i = 1;
 i = (2 + 3) * 10;
 i = 2 + 3 * 10;
 j = 6 % 4;
 k = i + j;
 return 0;
 exit(0);
 printf ("Howdy, neighbor! This is my first C
program.n");
 A group of statements can form a statement block that
starts with an opening brace ({) and ends with a closing
brace (}). A statement block is treated as a single
statement by the C compiler.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1;i<=20;i++)
{
textcolor(i);
cprintf("Computer Bak Touk Centernr");
}
getch();
}
 standard C library functions
 Functions are the building blocks of C programs
 printf() and exit()
 scanf()
 clrscr()
 gotoxy(x,y);
 textcolor();
 colorbackground()
Illegal Name The Rule
 2 (digit) A function name cannot start with a
digit.
 * (Asterisk) A function name cannot start with an
asterisk.
 + (Addition) A function name cannot start with
one of the arithmetic signs that are reserved C
keywords.
 . (dot) A function name cannot start with ..
 total-number A function name cannot contain a
minus sign.
 account'97 A function name cannot contain an
apostrophe.
void functionName()
{
……………………….
……………………….
}
Void function Name(parameter)
{
………………………
………………………
}
Returntype functionName()
{
………………………..
………………………..
}
Returntype functionName(parmeter)
{
………………………..
………………………..
}
#include<stdio.h>
#include<conio.h>
void info();
void header()
{
gotoxy(25,5);
printf("Computer BakTouk Centern");
gotoxy(24,7);
printf("------------------------");
}
void main()
{
clrscr();
header();
info();
getch();
}
void info()
{ gotoxy(25,10);
printf("Near Master sukisupnttt Tel: 011 11 11 11");
}
#include<stdio.h>
#include<conio.h>
Void sum(int a,int b);
void main()
{
int x=100,y=34;
sum(x,y);
getch();
}
void sum(int a,int b)
{
printf("100+34=%d",a+b);
}
#include<stdio.h>
int integeradd(int x, int y)
{
int result;
result=x+y;
return result;
}
int main()
{
int sum;
sum=integeradd(5,12);
printf("5+12 =%d",sum);
return 0;
}
#include<stdio.h>
int integer_add(int x, int y);
int main()
{
int sum;
sum=integer_add(5,12);
printf("5+12 =%d",sum);
return 0;
}
int integer_add(int x, int y)
{
int result;
result=x+y;
return result;
}
#include<stdio.h>
#include<conio.h>
void interFace();
void enterValue(float val1,float val2);
void main()
{
clrscr();
float val1,val2;
interFace();
enterValue(val1,val2);
getch();
}
void interFace()
{
textbackground(BLUE);
printf("Enter value1:t");cprintf(" nnr");
printf("Enter value2:t");cprintf(" ");printf(" ");cprintf(" + nnr");
printf("Result :t");cprintf(" ");
}
void enterValue(float value1,float value2)
{
gotoxy(20,1);scanf("%f",&value1);
gotoxy(20,3);scanf("%f",&value2);
gotoxy(20,5);printf("%.2f",value1+value2);
}
#include<stdio.h>
#include<conio.h>
void interFace();
float enterValue(float val1,float val2);
void main()
{
clrscr();
float val1,val2,result;
interFace();
result=enterValue(val1,val2);
gotoxy(20,5);printf("%.2f",result);
getch();
}
void interFace()
{
textbackground(BLUE);
printf("Enter value1:t");cprintf(" nnr");
printf("Enter value2:t");cprintf(" ");printf(" ");cprintf(" * nnr");
printf("Result :t");cprintf(" ");
}
float enterValue(float value1,float value2)
{
gotoxy(20,1);scanf("%f",&value1);
gotoxy(20,3);scanf("%f",&value2);
return value1*value2;
}
 The sin() function
 The cos() function
 The tan() function
 The pow() function
 The sqrt() function
#include <stdio.h>
#include <math.h>
main()
{
double x;
x = 45.0; /* 45 degree */
x *= 3.141593 / 180.0; /* convert to radians */
printf("The sine of 45 is: %f.n", sin(x));
printf("The cosine of 45 is: %f.n", cos(x));
printf("The tangent of 45 is: %f.n", tan(x));
return 0;
}
#include <stdio.h>
#include <math.h>
main()
{
double x, y, z;
x = 64.0;
y = 3.0;
z = 0.5;
printf("pow(64.0, 3.0) returns: %7.0fn", pow(x, y));
printf("sqrt(64.0) returns: %2.0fn", sqrt(x));
printf("pow(64.0, 0.5) returns: %2.0fn", pow(x, z));
return 0;
}
 The if statement
 The if-else statement
 The switch statement
 The break statement
 The continue statement
 The goto statement
 used to evaluate the conditions as well as to
make the decision whether the block of code
controlled by the statement is going to be
executed.
if (5>1) {
statement1;
statement2;
.
.
}
if (x > 0)
printf("The square root of x is: %fn", sqrt(x));
EX:
#include <stdio.h>
main()
{
char ch;
printf("Enter a charactern");
scanf("%c", &ch);
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch
=='o' || ch=='O' || ch == 'u' || ch == 'U')
printf("%c is a vowel.n", ch);
else
printf("%c is not a vowel.n", ch);
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textbackground(YELLOW);
cprintf(" Min and Max nr");
textbackground(BLUE);
printf("Enter value1:");cprintf(" nnr");
printf("Enter value2:");cprintf(" nnr");
printf("Enter value3:");cprintf(" nnr");
printf("Maximum: ");cprintf(" nnr");
printf("Minimum: ");cprintf(" nnr");
cprintf(" Max ");printf("t");cprintf(" Min ");
float val1,val2,val3;
gotoxy(18,2);scanf("%f",&val1);
gotoxy(18,4);scanf("%f",&val2);
gotoxy(18,6);scanf("%f",&val3);
float Min,Max;
if(val1>=val2 && val1>=val3) Max=val1;
if(val2>=val1 && val2>=val3) Max=val2;
if(val3>=val1 && val3>=val2) Max=val3;
gotoxy(18,8);printf("%.2f",Max);
if(val1<=val2 && val1<=val3) Min=val1;
if(val2<=val1 && val2<=val3) Min=val2;
if(val3<=val1 && val3<=val2) Min=val3;
gotoxy(18,10);printf("%.2f",Min);
getch();
}
Note: strcmp
-include<string.h>
-Syntax: int strcmp(st1,st2);
-If return 0 means st1==st2
-If return <0 means st1<st2
-If return >0 means st1>st2
-Convert to Upper case//int tolower(char)//int toupper(char)
#include <string.h>
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int length, i;
char *string = "this is a string";
length = strlen(string);
for (i=0; i<length; i++)
{
string[i] = toupper(string[i]);//tolower
}
printf("%sn",string);
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
clrscr();
textbackground(YELLOW);
cprintf(" Study and Class nr");
textbackground(BLUE);
printf("Maths :");cprintf(" nnr");
printf("Chemistry :");cprintf(" nnr");
printf("Biology :");cprintf(" nnr");
printf("Physics :");cprintf(" nnr");
printf("Average :");cprintf(" nnr");
printf("Result :");cprintf(" nnr");
printf("Class :");cprintf(" nnr");
cprintf(" OK ");printf("t");cprintf(" Cancel ");
float maths,chem,phys,bio;
gotoxy(18,2);scanf("%f",&maths);
gotoxy(18,4);scanf("%f",&chem);
gotoxy(18,6);scanf("%f",&bio);
gotoxy(18,8);scanf("%f",&phys);
gotoxy(18,10);printf("%.2f",(maths+chem+phys+bio)/4);
if((maths+chem+phys+bio)>=200) {
gotoxy(18,12);printf("Pass");
if((maths+chem+phys+bio)>=350){
gotoxy(18,14);printf("A");
getch();
exit(0);}
if((maths+chem+phys+bio)>=300){
gotoxy(18,14);printf("B+");
getch();
exit(0);}
if((maths+chem+phys+bio)>=200){
gotoxy(18,14);printf("C++");
getch();
exit(0);} }
if((maths+chem+phys+bio)<200)
{
gotoxy(18,12);printf("Fail");
if((maths+chem+phys+bio)<100){
gotoxy(18,14);printf("F");
getch();
exit(0);}
if((maths+chem+phys+bio)<200){
gotoxy(18,14);printf("E");
getch();
exit(0);} }
getch();}
 If(expression)
{
block of statement;
}
else
statement;
 use to make unlimited decisions or choices based on
the value of a conditional expression and specified
cases. Int, byte, short, char
switch (expression) {
case expression1:
statement1;
case expression2:
statement2;
.
.
.
default:
statement-default;
}
#include <stdio.h>
main()
{
int day;
printf("Please enter a single digit for a dayn");
printf("(within the range of 1 to 3):n");
day = getchar();
switch (day){
case `1':
printf("Day 1n");break;
case `2':
printf("Day 2n");break;
case `3':
printf("Day 3n");break;
default:
}
return 0;
}
Up = 72
Down = 80
Left =75
Right=77
Esc=27
 You can add a break statement at the end of
the statement list following every case label,
if you want to exit the switch construct after
the statements within a selected case are
executed. BREAK LOOP ALSO
#include <stdio.h>
main()
{
int day;
printf("Please enter a single digit for a
dayn");
printf("(within the range of 1 to 7):n");
day = getchar();
switch (day){
case `1':
printf("Day 1 is Sunday.n");
break;
case `2':
printf("Day 2 is Monday.n");
break;
case `3':
printf("Day 3 is Tuesday.n");
break;
case `4':
printf("Day 4 is Wednesday.n");
break;
case `5':
printf("Day 5 is Thursday.n");
break;
case `6':
printf("Day 6 is Friday.n");
break;
case `7':
printf("Day 7 is Saturday.n");
break;
default:
printf("The digit is not within the range of 1 to 7.n");
break;
}
return 0;
}
 Instead of breaking a loop, there are times
when you want to stay in a loop but skip over
some statements within the loop. To do this,
you can use the continue statement provided
by C. The continue statement causes
execution to jump to the top of the loop
immediately.
#include <stdio.h>
main()
{
int i, sum;
sum = 0;
for (i=1; i<8; i++){
if ((i==3) || (i==5))
continue;
sum += i;
}
printf("The sum of 1, 2, 4, 6, and 7 is: %dn",
sum);
return 0;
}
 Looping, called iteration, is used in
programming to perform the same set of
statements over and over until certain
specified conditions are met.
 The for statement
 The while statement
 The do-while statement
for (expression1; expression2; expression3)
{
statement1;
statement2;
.
.
.
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=0;i<3;)
{
printf(“Hello n”);
i++;
}
getch();
}
#include <stdio.h>
main()
{
int i, j;
for (i=0, j=8; i<8; i++, j--)
printf("%d + %d = %dn", i, j, i+j);
return 0;
}
for (i=0, j=10; i<10, j>0; i++, j--){
/* statement block */
}
Ex:
#include <stdio.h>
main()
{
int i, j;
for (i=0, j=8; i<8; i++, j--)
printf("%d + %d = %dn", i, j, i+j);
return 0;
}
#include <stdio.h>
main()
{
char c;
printf("Enter a character:n(enter x to exit)n");
for ( c=‘’; c != ‘x’; ) {
c = getc(stdin);
putchar(c);
}
printf("nOut of the for loop. Bye!n");
return 0;
}
 the expressions are set at the top of the loop
do {
statement1;
statement2;
.
.
.
} while (expression);
#include <stdio.h>
main()
{
int i;
i = 100;
do {
printf("The numeric value of %c is %d.n", i, i);
i++;
} while (i<72);
return 0;
}
while (expression) {
statement1;
statement2;
.
.
.
}
#include <stdio.h>
main()
{
char c;
printf("Enter a character:n(enter x to exit)n");
while (c != `x') {
c = getc(stdin);
putchar(c);
}
printf("nOut of the while loop. Bye!n");
return 0;
}
while (1) {
statement1;
statement2;
.
.
.
}

More Related Content

What's hot (20)

C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C questions
C questionsC questions
C questions
 
Function basics
Function basicsFunction basics
Function basics
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
C programms
C programmsC programms
C programms
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Double linked list
Double linked listDouble linked list
Double linked list
 
C program
C programC program
C program
 
C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5
 
Single linked list
Single linked listSingle linked list
Single linked list
 

Viewers also liked

Quoting, concluding, tips
Quoting, concluding, tipsQuoting, concluding, tips
Quoting, concluding, tipscvergarapalza
 
تقرير المعمل القانونى
تقرير المعمل القانونىتقرير المعمل القانونى
تقرير المعمل القانونىHassan Ibrahim
 
myThings - NOAH13 London
myThings - NOAH13 LondonmyThings - NOAH13 London
myThings - NOAH13 LondonNOAH Advisors
 
8 Benefits of Moving QuickBooks Desktop to Cloud
8 Benefits of Moving QuickBooks Desktop to Cloud8 Benefits of Moving QuickBooks Desktop to Cloud
8 Benefits of Moving QuickBooks Desktop to CloudMonika Goel
 
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...Mohammed Almeshekah
 
امن الشبكات ccnas
امن الشبكات ccnasامن الشبكات ccnas
امن الشبكات ccnasrami alamoudi
 
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezer
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezerDa vinci gibi düşünmek için sihir şart mı tanyer sonmezer
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezerTanyer Sonmezer
 
Katli değerin şifresi 2016 tanyer sonmezer
Katli değerin şifresi 2016 tanyer sonmezerKatli değerin şifresi 2016 tanyer sonmezer
Katli değerin şifresi 2016 tanyer sonmezerTanyer Sonmezer
 
To Kill A Mockingbird Symbol Of Innocence
To Kill A Mockingbird Symbol Of InnocenceTo Kill A Mockingbird Symbol Of Innocence
To Kill A Mockingbird Symbol Of Innocencetranceking
 
Social media as opinion generator
Social media as opinion generatorSocial media as opinion generator
Social media as opinion generatorMou Mukherjee-Das
 
How to Develop Writing Skill
How to Develop Writing SkillHow to Develop Writing Skill
How to Develop Writing SkillRajeev Ranjan
 
Les Français et la nouvelle société collaborative
Les Français et la nouvelle société collaborativeLes Français et la nouvelle société collaborative
Les Français et la nouvelle société collaborativeKantar
 

Viewers also liked (18)

(Why) Will Agile Work This Time
(Why) Will Agile Work This Time(Why) Will Agile Work This Time
(Why) Will Agile Work This Time
 
Quoting, concluding, tips
Quoting, concluding, tipsQuoting, concluding, tips
Quoting, concluding, tips
 
تقرير المعمل القانونى
تقرير المعمل القانونىتقرير المعمل القانونى
تقرير المعمل القانونى
 
myThings - NOAH13 London
myThings - NOAH13 LondonmyThings - NOAH13 London
myThings - NOAH13 London
 
Operaciones y funciones de matrices
Operaciones y funciones de matricesOperaciones y funciones de matrices
Operaciones y funciones de matrices
 
BLT_Info_eng
BLT_Info_engBLT_Info_eng
BLT_Info_eng
 
8 Benefits of Moving QuickBooks Desktop to Cloud
8 Benefits of Moving QuickBooks Desktop to Cloud8 Benefits of Moving QuickBooks Desktop to Cloud
8 Benefits of Moving QuickBooks Desktop to Cloud
 
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...
Using Deception to Enhance Security: A Taxonomy, Model, and Novel Uses -- The...
 
امن الشبكات ccnas
امن الشبكات ccnasامن الشبكات ccnas
امن الشبكات ccnas
 
Emportedomicile
EmportedomicileEmportedomicile
Emportedomicile
 
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezer
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezerDa vinci gibi düşünmek için sihir şart mı tanyer sonmezer
Da vinci gibi düşünmek için sihir şart mı tanyer sonmezer
 
منهجية قانون الانترنيت
منهجية قانون الانترنيتمنهجية قانون الانترنيت
منهجية قانون الانترنيت
 
Katli değerin şifresi 2016 tanyer sonmezer
Katli değerin şifresi 2016 tanyer sonmezerKatli değerin şifresi 2016 tanyer sonmezer
Katli değerin şifresi 2016 tanyer sonmezer
 
Dinamika pedosfer
Dinamika pedosferDinamika pedosfer
Dinamika pedosfer
 
To Kill A Mockingbird Symbol Of Innocence
To Kill A Mockingbird Symbol Of InnocenceTo Kill A Mockingbird Symbol Of Innocence
To Kill A Mockingbird Symbol Of Innocence
 
Social media as opinion generator
Social media as opinion generatorSocial media as opinion generator
Social media as opinion generator
 
How to Develop Writing Skill
How to Develop Writing SkillHow to Develop Writing Skill
How to Develop Writing Skill
 
Les Français et la nouvelle société collaborative
Les Français et la nouvelle société collaborativeLes Français et la nouvelle société collaborative
Les Français et la nouvelle société collaborative
 

Similar to 3. chapter ii

Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structureHarithaRanasinghe
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxTasnimSaimaRaita
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
 

Similar to 3. chapter ii (20)

7 functions
7  functions7  functions
7 functions
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptx
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
What is c
What is cWhat is c
What is c
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
3. control statement
3. control statement3. control statement
3. control statement
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 

More from Chhom Karath

More from Chhom Karath (20)

set1.pdf
set1.pdfset1.pdf
set1.pdf
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
 
Bracket size
Bracket sizeBracket size
Bracket size
 
Couple
CoupleCouple
Couple
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
 
Game1
Game1Game1
Game1
 
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
 
Opus loop
Opus loopOpus loop
Opus loop
 
V bend
V bendV bend
V bend
 
Closing loop
Closing loopClosing loop
Closing loop
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
 

Recently uploaded

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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
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
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

3. chapter ii

  • 2.  C program is made of basic elements, such as expressions, statements, statement blocks, and function blocks.  Constant is a value that never changes  Variables can be used to present different values  Expression: is a combination of constants, variables, and operators that are used to denote computations.  6 An expression of a constant.  i An expression of a variable.  6 + i An expression of a constant plus a variable.  exit(0) An expression of a function call.
  • 3.
  • 4.  Arithmetic Operators  + Addition  - Subtraction  * Multiplication  / Division  % Remainder (or modulus)(6%4=2)  Note:  2 + 3 * 10  (2+ (3 * 10))
  • 5.  statement is a complete instruction, ending with a semicolon.  i = 1;  i = (2 + 3) * 10;  i = 2 + 3 * 10;  j = 6 % 4;  k = i + j;  return 0;  exit(0);  printf ("Howdy, neighbor! This is my first C program.n");
  • 6.  A group of statements can form a statement block that starts with an opening brace ({) and ends with a closing brace (}). A statement block is treated as a single statement by the C compiler. #include<stdio.h> #include<conio.h> void main() { clrscr(); int i; for(i=1;i<=20;i++) { textcolor(i); cprintf("Computer Bak Touk Centernr"); } getch(); }
  • 7.  standard C library functions  Functions are the building blocks of C programs  printf() and exit()  scanf()  clrscr()  gotoxy(x,y);  textcolor();  colorbackground()
  • 8. Illegal Name The Rule  2 (digit) A function name cannot start with a digit.  * (Asterisk) A function name cannot start with an asterisk.  + (Addition) A function name cannot start with one of the arithmetic signs that are reserved C keywords.  . (dot) A function name cannot start with ..  total-number A function name cannot contain a minus sign.  account'97 A function name cannot contain an apostrophe.
  • 9.
  • 10. void functionName() { ………………………. ………………………. } Void function Name(parameter) { ……………………… ……………………… } Returntype functionName() { ……………………….. ……………………….. } Returntype functionName(parmeter) { ……………………….. ……………………….. }
  • 11. #include<stdio.h> #include<conio.h> void info(); void header() { gotoxy(25,5); printf("Computer BakTouk Centern"); gotoxy(24,7); printf("------------------------"); } void main() { clrscr(); header(); info(); getch(); } void info() { gotoxy(25,10); printf("Near Master sukisupnttt Tel: 011 11 11 11"); }
  • 12. #include<stdio.h> #include<conio.h> Void sum(int a,int b); void main() { int x=100,y=34; sum(x,y); getch(); } void sum(int a,int b) { printf("100+34=%d",a+b); }
  • 13. #include<stdio.h> int integeradd(int x, int y) { int result; result=x+y; return result; } int main() { int sum; sum=integeradd(5,12); printf("5+12 =%d",sum); return 0; }
  • 14. #include<stdio.h> int integer_add(int x, int y); int main() { int sum; sum=integer_add(5,12); printf("5+12 =%d",sum); return 0; } int integer_add(int x, int y) { int result; result=x+y; return result; }
  • 15. #include<stdio.h> #include<conio.h> void interFace(); void enterValue(float val1,float val2); void main() { clrscr(); float val1,val2; interFace(); enterValue(val1,val2); getch(); } void interFace() { textbackground(BLUE); printf("Enter value1:t");cprintf(" nnr"); printf("Enter value2:t");cprintf(" ");printf(" ");cprintf(" + nnr"); printf("Result :t");cprintf(" "); } void enterValue(float value1,float value2) { gotoxy(20,1);scanf("%f",&value1); gotoxy(20,3);scanf("%f",&value2); gotoxy(20,5);printf("%.2f",value1+value2); }
  • 16. #include<stdio.h> #include<conio.h> void interFace(); float enterValue(float val1,float val2); void main() { clrscr(); float val1,val2,result; interFace(); result=enterValue(val1,val2); gotoxy(20,5);printf("%.2f",result); getch(); } void interFace() { textbackground(BLUE); printf("Enter value1:t");cprintf(" nnr"); printf("Enter value2:t");cprintf(" ");printf(" ");cprintf(" * nnr"); printf("Result :t");cprintf(" "); } float enterValue(float value1,float value2) { gotoxy(20,1);scanf("%f",&value1); gotoxy(20,3);scanf("%f",&value2); return value1*value2; }
  • 17.  The sin() function  The cos() function  The tan() function  The pow() function  The sqrt() function
  • 18. #include <stdio.h> #include <math.h> main() { double x; x = 45.0; /* 45 degree */ x *= 3.141593 / 180.0; /* convert to radians */ printf("The sine of 45 is: %f.n", sin(x)); printf("The cosine of 45 is: %f.n", cos(x)); printf("The tangent of 45 is: %f.n", tan(x)); return 0; } #include <stdio.h> #include <math.h> main() { double x, y, z; x = 64.0; y = 3.0; z = 0.5; printf("pow(64.0, 3.0) returns: %7.0fn", pow(x, y)); printf("sqrt(64.0) returns: %2.0fn", sqrt(x)); printf("pow(64.0, 0.5) returns: %2.0fn", pow(x, z)); return 0; }
  • 19.  The if statement  The if-else statement  The switch statement  The break statement  The continue statement  The goto statement
  • 20.  used to evaluate the conditions as well as to make the decision whether the block of code controlled by the statement is going to be executed. if (5>1) { statement1; statement2; . . } if (x > 0) printf("The square root of x is: %fn", sqrt(x));
  • 21. EX: #include <stdio.h> main() { char ch; printf("Enter a charactern"); scanf("%c", &ch); if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U') printf("%c is a vowel.n", ch); else printf("%c is not a vowel.n", ch); return 0; }
  • 22. #include<stdio.h> #include<conio.h> void main() { clrscr(); textbackground(YELLOW); cprintf(" Min and Max nr"); textbackground(BLUE); printf("Enter value1:");cprintf(" nnr"); printf("Enter value2:");cprintf(" nnr"); printf("Enter value3:");cprintf(" nnr"); printf("Maximum: ");cprintf(" nnr"); printf("Minimum: ");cprintf(" nnr"); cprintf(" Max ");printf("t");cprintf(" Min "); float val1,val2,val3; gotoxy(18,2);scanf("%f",&val1); gotoxy(18,4);scanf("%f",&val2); gotoxy(18,6);scanf("%f",&val3); float Min,Max; if(val1>=val2 && val1>=val3) Max=val1; if(val2>=val1 && val2>=val3) Max=val2; if(val3>=val1 && val3>=val2) Max=val3; gotoxy(18,8);printf("%.2f",Max); if(val1<=val2 && val1<=val3) Min=val1; if(val2<=val1 && val2<=val3) Min=val2; if(val3<=val1 && val3<=val2) Min=val3; gotoxy(18,10);printf("%.2f",Min); getch(); }
  • 23. Note: strcmp -include<string.h> -Syntax: int strcmp(st1,st2); -If return 0 means st1==st2 -If return <0 means st1<st2 -If return >0 means st1>st2 -Convert to Upper case//int tolower(char)//int toupper(char) #include <string.h> #include <stdio.h> #include <ctype.h> int main(void) { int length, i; char *string = "this is a string"; length = strlen(string); for (i=0; i<length; i++) { string[i] = toupper(string[i]);//tolower } printf("%sn",string); return 0; }
  • 24.
  • 25. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { clrscr(); textbackground(YELLOW); cprintf(" Study and Class nr"); textbackground(BLUE); printf("Maths :");cprintf(" nnr"); printf("Chemistry :");cprintf(" nnr"); printf("Biology :");cprintf(" nnr"); printf("Physics :");cprintf(" nnr"); printf("Average :");cprintf(" nnr"); printf("Result :");cprintf(" nnr"); printf("Class :");cprintf(" nnr"); cprintf(" OK ");printf("t");cprintf(" Cancel "); float maths,chem,phys,bio; gotoxy(18,2);scanf("%f",&maths); gotoxy(18,4);scanf("%f",&chem); gotoxy(18,6);scanf("%f",&bio); gotoxy(18,8);scanf("%f",&phys); gotoxy(18,10);printf("%.2f",(maths+chem+phys+bio)/4);
  • 27.
  • 28.  If(expression) { block of statement; } else statement;
  • 29.  use to make unlimited decisions or choices based on the value of a conditional expression and specified cases. Int, byte, short, char switch (expression) { case expression1: statement1; case expression2: statement2; . . . default: statement-default; }
  • 30. #include <stdio.h> main() { int day; printf("Please enter a single digit for a dayn"); printf("(within the range of 1 to 3):n"); day = getchar(); switch (day){ case `1': printf("Day 1n");break; case `2': printf("Day 2n");break; case `3': printf("Day 3n");break; default: } return 0; }
  • 31. Up = 72 Down = 80 Left =75 Right=77 Esc=27
  • 32.  You can add a break statement at the end of the statement list following every case label, if you want to exit the switch construct after the statements within a selected case are executed. BREAK LOOP ALSO
  • 33. #include <stdio.h> main() { int day; printf("Please enter a single digit for a dayn"); printf("(within the range of 1 to 7):n"); day = getchar(); switch (day){ case `1': printf("Day 1 is Sunday.n");
  • 34. break; case `2': printf("Day 2 is Monday.n"); break; case `3': printf("Day 3 is Tuesday.n"); break; case `4': printf("Day 4 is Wednesday.n"); break; case `5': printf("Day 5 is Thursday.n"); break; case `6': printf("Day 6 is Friday.n"); break; case `7': printf("Day 7 is Saturday.n"); break; default: printf("The digit is not within the range of 1 to 7.n"); break; } return 0; }
  • 35.
  • 36.  Instead of breaking a loop, there are times when you want to stay in a loop but skip over some statements within the loop. To do this, you can use the continue statement provided by C. The continue statement causes execution to jump to the top of the loop immediately.
  • 37. #include <stdio.h> main() { int i, sum; sum = 0; for (i=1; i<8; i++){ if ((i==3) || (i==5)) continue; sum += i; } printf("The sum of 1, 2, 4, 6, and 7 is: %dn", sum); return 0; }
  • 38.  Looping, called iteration, is used in programming to perform the same set of statements over and over until certain specified conditions are met.  The for statement  The while statement  The do-while statement
  • 39.
  • 40. for (expression1; expression2; expression3) { statement1; statement2; . . . }
  • 42. #include <stdio.h> main() { int i, j; for (i=0, j=8; i<8; i++, j--) printf("%d + %d = %dn", i, j, i+j); return 0; }
  • 43. for (i=0, j=10; i<10, j>0; i++, j--){ /* statement block */ } Ex: #include <stdio.h> main() { int i, j; for (i=0, j=8; i<8; i++, j--) printf("%d + %d = %dn", i, j, i+j); return 0; }
  • 44. #include <stdio.h> main() { char c; printf("Enter a character:n(enter x to exit)n"); for ( c=‘’; c != ‘x’; ) { c = getc(stdin); putchar(c); } printf("nOut of the for loop. Bye!n"); return 0; }
  • 45.
  • 46.  the expressions are set at the top of the loop do { statement1; statement2; . . . } while (expression);
  • 47. #include <stdio.h> main() { int i; i = 100; do { printf("The numeric value of %c is %d.n", i, i); i++; } while (i<72); return 0; }
  • 49. #include <stdio.h> main() { char c; printf("Enter a character:n(enter x to exit)n"); while (c != `x') { c = getc(stdin); putchar(c); } printf("nOut of the while loop. Bye!n"); return 0; }

Editor's Notes

  1. #include<stdio.h> #include<conio.h> void main() { clrscr(); int x=1,y=1; char type; bb: gotoxy(x,y);printf("MY PCCCCC"); type=getch(); switch(type) { case 72:clrscr();y--; if(y<1) y=25; gotoxy(x,y);printf("MY PCCCCC"); break; case 80:clrscr();y++; if(y>25) y=1; gotoxy(x,y);printf("MY PCCCCC"); break; case 77:clrscr();x++; if(x>70) x=1; gotoxy(x,y);printf("MY PCCCCC"); break; case 75:clrscr();x--; if(x<1) x=70; gotoxy(x,y);printf("MY PCCCCC"); break; case 27:goto stop; default: gotoxy(x,y); printf("My PCCCCC"); } goto bb; stop: }
  2. #include<stdio.h> #include<conio.h> void main() { clrscr(); _setcursortype(_NOCURSOR); printf("Enter value 1: "); textbackground(GREEN); cprintf(" \n\n\r"); printf("Enter value 1: "); cprintf(" \n\n\r"); printf("The result : "); cprintf(" \n\n\r"); textbackground(RED); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" \n\r"); cprintf(" +(s) ");printf(" "); cprintf(" -(n) ");printf(" "); cprintf(" *(m) ");printf(" "); cprintf(" /(d) ");printf(" "); cprintf(" clear(c) ");printf(" \n\r"); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" "); cprintf(" ");printf(" "); float v1,v2,result; char ch; back: gotoxy(26,1);scanf("%f",&v1); gotoxy(26,3);scanf("%f",&v2); fflush(stdin); gotoxy(26,13); ch=getch(); back2: if(ch=='s') { result=v1+v2; } else if(ch=='m') { result=v1*v2; } else if(ch=='d') { result=v1/v2; } else if(ch=='l') { result=(int)v1 % (int)v2; } else if(ch=='n') { result=v1-v2; } gotoxy(26,5); printf("%.2f",result); char ag; gotoxy(26,13); fflush(stdin); ag=getch(); if(ag=='c') { textbackground(GREEN); gotoxy(17,1); cprintf(" "); gotoxy(17,3); cprintf(" "); gotoxy(17,5); cprintf(" "); goto back; } else if(ag==27) { goto stop; } ch=ag; goto back2; getch(); stop: }
  3. #include<stdio.h> #include<conio.h> main() { int year,day; char ch; for(;ch!=27;) { clrscr(); printf("Please Enter The Year:"); scanf("%d",&year); day=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7; switch(day) { case 0:printf("Sunday 1st January %d",year);break; case 1:printf("Monday 1st January %d",year);break; case 2:printf("Tuesday 1st January %d",year);break; case 3:printf("Wednesday 1st January %d",year);break; case 4:printf("Thursday 1st January %d",year);break; case 5:printf("Friday 1st January %d",year);break; case 6:printf("Saturday 1st January %d",year);break; } ch=getch(); } return 0; }