0% found this document useful (0 votes)
12 views

Functions

management functions

Uploaded by

brahim.safa2018
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Functions

management functions

Uploaded by

brahim.safa2018
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Functions

int swap( int a, int b) // by reference


#include <stdio.h>
Var temp : integer void swap(int *a,int *b)
Begin {
int temp;
1- temp = a temp=*a;
*a=*b;
2- a=b
*b=temp;
3- b=temp }
int main()
End swap {
Algorithm Addition int a,b;
printf("a=");
Var a,b, addition : integer scanf("%d",&a);
printf("b=");
Begin
scanf("%d",&b);
1- write(“please enter two swap(&a,&b);
integer values”) printf("%d \n",a);
printf("%d \n",b);
2- read(a,b) }
3- swap(a,b) // by value does not change
/*#include <stdio.h>
4- write (a,b) void swap(int a,int b)
{
End int temp;
temp=a;
a=b;
b=temp;
}
int main()
{
int a,b;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
swap(a,b);
printf("%d \n",a);
printf("%d \n",b);
}*/
#include <stdio.h> #include <stdio.h>
void average(int A[],int lenth) #include <stdlib.h>
{ float avg(int a[],int n){
int sum=0,i,ave; int i,s;
for (i=0;i<lenth;i++) for(i=0;i<n;i++){
{ s+=a[i];
sum=sum+A[i]; }
} return (s/n);
ave= sum/lenth; }
printf("the average is %d \n" ,ave);
}
int max( int a[],int n){
void max(int A[],int lenth)
int max=a[0],i;
{
for(i=1;i<n;i++){
int max=A[0],i;
if(a[i]>max)
for (i=1;i<lenth;i++)
max=a[i];
{
}
if (A[i]>max)
return max;
{
}
max=A[i];
int min(int a[],int n){
}
int i ,min=a[0];
}
for(i=1;i<n;i++){
printf("the max is %d \n ",max);
if(a[i]<min)
}
min=a[i];
void min(int A[],int lenth)
}
{
return min;
int min=A[0],i;
}
for (i=1;i<lenth;i++)
int main()
{
{
if (A[i]<min)
int n;
{
min=A[i]; printf("Give the length of the
} sequence");scanf("%d",&n);
} int a[n],i;
printf("the min is %d \n ",min);
}
printf("Give a sequence of
int main() { positive integers");
int A[100],size,n,lenth=0,i=0; for(i=0; i<n;i++){
printf("enter the number of do{
integers:"); printf("a[%d]=",i);scanf("%d",&
scanf("%d",&size); a[i]);
}while(a[i]<0);
}
printf("The average is: %.2f\
n",avg(a,n));
printf("The max is: %d\
n",max(a,n));
printf("The min is: %d\
#include <stdio.h>
int armstrong(int p) #include <stdio.h>
{ #include <stdlib.h>
int i,n=0,x,j,sum=0; void armstrong(){
x=p; int i;
i=p; for(i=0;i<=999;i++){
//number of digits of the integer: int a=i/100;
while (x!=0)
{
int b=(i%100)/10;
x/=10; int c=(i%10);
n+=1; if ((a*a*a+b*b*b+c*c*c)==i)
} printf("%d\n",i);
for (j=0;j<n;j++) }
{
x=i%10;
i=i/10;
sum=sum+(x*x*x);
}
}
if(sum==p) int main()
{ {
return 1; int a,i,k;
}
else printf("All Armstrong
{ numbers between 0 and 999
return 0; are: ");
}
}
printf("\n");
main() printf("Calculating:");
{ for(i=0;i<5;i++){
int i; for(k=0;k<1000000000;k++)
for(i=0;i<999;i++) a=0;
{ printf(".");
if (armstrong(i)==1)
{
}
printf("the number %d is armastrong \n
",i);
printf("\n");
} armstrong();
}
}

return 0;
}
#include <stdio.h> #include <stdio.h>
void fill(int A[]) #include <stdlib.h>
{ void reading(int a[],int n){
int i; int i;
for (i=0;i<10;i++) for(i=0;i<n;i++){
{ printf("a[%d]=",i);scanf("%
printf("A[%d] :\t", i+1); d",&a[i]);
scanf("%d",&A[i]); }
}
}

void affiche(int A[]) }


{ void upgread(int a[],int
int i; v,int n){
for(i=0;i<10;i++) int i,s=-1;
{ for(i=0;i<n;i++){
printf("%d \n", A[i]); if(a[i]==v){
} s=i;
} break;
void update(int A[],int v) }}
{ if (s!=-1){
int i,j=0,search=0; printf("%d does exist\n",v);
do for(i=s;i<=(n-1);i++){
{ a[i]=a[i+1];
if(A[j]==v) }
{ a[n-1]=0;
search=1;
i=j; }
printf("the number exists in the array \ else
n"); printf("The number doesn't
break; exist ");
}
j=j+1;
}
}while(j<9);
void print(int a[],int n){
if(search==1)
{
for(j=i;j<10;j++)
{
A[j]=A[j+1];
}
A[9]=0;
}
}
main()
{
int A[20],v;
printf("enter the value: ");
scanf("%d \n",&v);
1

#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b){
int temp=*a;
*a=*b;
*b=temp;

}
int main()
{
int a,b;
printf("Give an integer a: ");scanf("%d",&a);
printf("Give an integer b: ");scanf("%d",&b);
swap(&a,&b);
printf("a=%d\n",a);printf("b=%d",b);
return 0;
}

You might also like