ملخص لغة البرمجة c
ملخص لغة البرمجة c
ملخص لغة البرمجة c
منظمة رموز
C language is a structured language it uses some notations
#include <stdio.h> is a directive C preprocessor.
int main() : main is a program building block called function. Everything
تنفيذه
is C begins executing at function main.
• The entire line is called a statement. Semi colon at the end of the
statement is called terminator. Every statement has this
terminator.
#include<stdio.h>
int main(){
char where[]="here";
printf("I want to stay %s", where);
int gimmyage= 33;
printf("\ngimmy is now %d",gimmyage);
return 0;
}
Data type in C language:
1) Numpers
a- Integers : countable numbers ( 1/28/2222/10000000/65656 )
int age = 45
b- Decimal number ( 2.5/3.66/10.5)
double gpa = 3.5
float price= 221.2
2) Character
a) we use ( char ……… = “ A” to store only one character in
storage
b) we use ( char……..[]=”ajckaj”; to store a phrase (bunch of
characters) in storage
if we but unsigned before any of them we can storage only positive
numbers and double value
also we have long int and short int these can maximized or minimized
the value which int can hold
prinntf specialize
to print symbols we cant print normally we have to put \ before th
symbol
example :
printf(“fuck u “ brad”); it should be like this printf(“fuck u \“ brad”);
%s to deified a phrase like > printf(“I love %s”, “football”);
%f to deified a Decimal or float number like > printf(“I love %f”, 500.32);
%d to deified a normal number like > printf(“I love %d”, 56);
%c to deified a character like > printf(“I love %c”,”a” );
char name[20];
printf("enter your name: ");
fgets(name , 20,stdin);
printf("your name is: %s", name);
Coding a calculater :
#include <stdio.h>
int main()
{
int num1;
int num2;
printf("enter the first number: ");
scanf("%d",&num1);
printf("enter the seconed number: ");
scanf("%d",&num2);
printf("the total is : %d",num1 + num2);
return 0;
}
Defining a function :
Defining a function in C language means creating a block of code that
performs a specific task and can be reused in the program
int main() {
int result;
// Function call
result = add(5, 3);
// Print result
printf("The sum is: %d\n", result);
return 0;
}
// Function definition
Definition after
int add(int a, int b) { intmain()
return a + b; // Returns the sum of a and b
}
İf statment :
İn if statment && means and , || means or
Unsigned counter
نستخدم معه%u
int grade;
int total;
double average;
total= 0;
counter= 0;
printf("%s","enter your grade,-1 to end:");
scanf("%d",&grade);
while (grade!= -1){
total=total+grade;
counter=counter+1 ;
printf("%s","enter your grade,-1 to end:");
scanf("%d",&grade);}
if ( counter!= 0){
average = (float)total/counter;
printf("class average is %.2f\n", average);
}
else{
puts("no grades enter");
}
}
Examitation results:
#include <stdio.h>
int main(void) {
unsigned int student=1;
unsigned int passes=0;
unsigned int failurs=0;
int result;
while (student<=10){
puts("enter your grade(1=pass 0=fail)");
scanf("%d",&result);
if (result==1){
passes=passes+1;
}
else{
failurs=failurs+1;
}
student=student+1;
printf("passed%u\n",passes);
printf("faild%u\n",failurs);
if(passes>8){
puts("bounus to akdeja") ;
}
}
}
variable)(operator)(expression); c=c+3
Where operator is binary operator of (+)(-)(*)(/) or (%) can be written in
the form:
Variable operator = expression; c+=3
C+=3 c=c+3 adds 3 to c
d+=4 d=d+4
e*=5 e=e*5
For is a loop give us the same work as while but less steps
#include <stdio.h>
#include <math.h>
int main()
{
int n, i, isPrime = 1;
printf("n=");
scanf_s("%d", &n);
if ((n % 2) == 0 && n > 2)
{
isPrime = 0;
}
else
{
for (i = 3; i < (n / 2); i = i + 2)
{
if ((n % i) == 0)
{
isPrime = 0;
break;
}
}
}
if (isPrime == 1)
{
printf("The number is Prime"); }
else
{
printf("The number is Not Prime");
}
return 0;
}