A
C Programming Course
Eng. Mohamed Yousef
(Slides Book)
Egypt, 2020
The link of C programming course on my youtube channel is:
https://www.youtube.com/playlist?list=PLfgCIULRQavzxY-IO2sO5Vj5x7C_tjW3R
Follow me on:
https://www.youtube.com/mohamedyousef2
https://electronics010.blogspot.com/
https://www.facebook.com/electronics010
B
Resources
Books:
C Programming for the absolute beginner
Beginning programming with C for dummies
C _ how to program
Websites:
https://www.geeksforgeeks.org/c-programming-language/
https://www.tutorialspoint.com/cprogramming/
https://codeforwin.org/2017/08/introduction-c-programming.html
https://microchipdeveloper.com/tls2101:start
In addition to many scattered web pages.
/*
============================================================================
==
PROGRAM : Lab01-1
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#define NUMB_1 -3000000000
#define NUMB_2 12.3456
#define FLAG 'T'
int main()
{
return 0;
}
/*
============================================================================
==
PROGRAM : Lab01-2
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
const signed long long int NUMB_1 = -3000000000;
const float NUMB_2 = 12.3456;
const char FLAG = 'T';
int main()
{
return 0;
}
#include <stdio.h>
int main()
{
char operator_char;
double firstNumber,secondNumber;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator_char);
printf("Enter two operands: ");
scanf("%lf %lf",&firstNumber, &secondNumber);
switch(operator_char)
{
case '+': // ASCII => 43
printf("%g + %g = %g",firstNumber, secondNumber, firstNumber +
secondNumber);
break;
case '-': // ASCII => 45
printf("%g - %g = %g",firstNumber, secondNumber, firstNumber -
secondNumber);
break;
case '*': // ASCII => 42
printf("%g * %g = %g",firstNumber, secondNumber, firstNumber *
secondNumber);
break;
case '/': // ASCII => 47
if(secondNumber == 0){
printf("second number is ZERO!\n");
} else {
printf("%g / %g = %g",firstNumber, secondNumber,
firstNumber / secondNumber);
}
break;
// operator doesn't match any case constant (+, -, *, /)
default:
printf("Error! operator is not correct");
}
return 0;
}
/*
============================================================================
==
PROGRAM :
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#include <stdio.h>
#define true 1
int main(void){
int students_number = 0;
float degree = 0.0, sum = 0.0;
printf("\n Enter negative number to finish. \n");
while(true){
students_number++;
printf(" Enter student %d degree : ", students_number);
scanf("%f", °ree);
if(degree < 0) break;
sum += degree;
}
students_number--;
if(students_number != 0){
printf("\n Average student degree is : %g", sum / students_number);
}
return 0;
}
/*
============================================================================
==
PROGRAM : circle Area
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#include <stdio.h>
float Circle_Area(float radius);
/* -----------------------------------------------------------------------
*/
int main(){
float radius = 0.0, area = 0.0;
printf("\n Enter the radius of Circle : ");
scanf("%f", &radius);
area = Circle_Area(radius);
printf(" Area of Circle : %f\n", area);
return 0;
}
/* -----------------------------------------------------------------------
*/
float Circle_Area(float radius){
return (radius * radius * 3.1416);
}
/* -----------------------------------------------------------------------
*/
#include <stdio.h>
int x = 5; // global variable
void func(int);
int main(void){
printf("\n Before function call : %d", x);
int x = 10; // local variable declaration
func(x);
printf("\n After function call : %d", x);
return 0;
}
void func(int x){
printf("\n From function : %d", x);
x = 15;
}
/*
============================================================================
==
PROGRAM : single file project
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#include <stdio.h>
// variables
int operation = 0;
float operand1 = 0, operand2 = 0;
// constants
#define ADD 1
#define SUB 2
// prototypes
void Title(void);
void Get_User_Inputs(void);
void Add(void);
void Sub(void);
//
---------------------------------------------------------------------------
int main(){
Title();
Get_User_Inputs();
switch(operation){
case ADD: Add(); break;
case SUB: Sub(); break;
default: printf("\n Tanks");
}
return 0;
}
//
---------------------------------------------------------------------------
void Title(void){
printf("\n\t\tCalculator Program");
printf("\n\t\t==================\n");
}
//
---------------------------------------------------------------------------
void Get_User_Inputs(void){
printf("\n 1- Addition.");
printf("\n 2- Subtraction.");
printf("\n Select Operation :");
scanf("%d", &operation);
printf("\n Enter 1st operand :");
scanf("%f", &operand1);
printf(" Enter 2nd operand :");
scanf("%f", &operand2);
}
//
---------------------------------------------------------------------------
void Add(void){
printf("\n %g + %g = %g", operand1, operand2, (operand1 + operand2));
}
//
---------------------------------------------------------------------------
void Sub(void){
printf("\n %g - %g = %g", operand1, operand2, (operand1 - operand2));
}
//
---------------------------------------------------------------------------
/*
============================================================================
==
PROGRAM : multi files project
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#include "calculator.h"
//
---------------------------------------------------------------------------
int main(){
Calculator();
return 0;
}
#ifndef CALCULATOR_H_INCLUDED
#define CALCULATOR_H_INCLUDED
extern void Calculator(void);
#endif // CALCULATOR_H_INCLUDED
/*
============================================================================
==
PROGRAM : multi files project
Author : Mohamed Sayed Yousef
http://electronics010.blogspot.com.eg/
Date : September 2018
Version : 1.0
Description :
============================================================================
==
*/
#include <stdio.h>
// variables
static int operation = 0;
static float operand1 = 0, operand2 = 0;
// constants
#define ADD 1
#define SUB 2
// prototypes
void Calculator(void);
static void Title(void);
static void Get_User_Inputs(void);
static void Add(void);
static void Sub(void);
//
---------------------------------------------------------------------------
void Calculator(void){
Title();
Get_User_Inputs();
switch(operation){
case ADD: Add(); break;
case SUB: Sub(); break;
default: printf("\n Tanks");
}
}
//
---------------------------------------------------------------------------
static void Title(void){
printf("\n\t\tCalculator Program");
printf("\n\t\t==================\n");
}
//
---------------------------------------------------------------------------
static void Get_User_Inputs(void){
printf("\n 1- Addition.");
printf("\n 2- Subtraction.");
printf("\n Select Operation :");
scanf("%d", &operation);
printf("\n Enter 1st operand :");
scanf("%f", &operand1);
printf(" Enter 2nd operand :");
scanf("%f", &operand2);
}
//
---------------------------------------------------------------------------
static void Add(void){
printf("\n %g + %g = %g", operand1, operand2, (operand1 + operand2));
}
//
---------------------------------------------------------------------------
static void Sub(void){
printf("\n %g - %g = %g", operand1, operand2, (operand1 - operand2));
}
//
---------------------------------------------------------------------------