You are on page 1of 6

9

:
10 10
#include <stdio.h>
#define N 10
int main()
{
int arr[N][N];
int i, j, avg;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
scanf(%d,&arr*i+*j+);
for (i = 0; i < N; i++)
{
avg = 0;
for (j = 0; j < N; j++)
avg += arr[i][j];
printf("grade for %d is%d: \n" ,i+1, avg/N);
}
}
Initialization:
1st way: with 2 loops (as seen above)
2nd way: at the creation line (example below)
int arr[2][3]={ {1,2,3},{2,2,2}};
sending to function:
at the declaration line of the function when you expect a function you must have a value at
the right brackets. E.g:
void func1(int arr[][4])
{
Blah
Blah
}
int main()
{
int table[3][4];
blah;
func1(table);
}

Avshalom Elmalech 83-120

Const array:
We can define a const array/function that get const array. E.g:
Const int arr[3] ={2,3,4};
Int func1(const int num[]);
:
. '\ 0'
:
#include <stdio.h>
int main()
{
char str*20+= ,I, ,H,A,V,E, ,A, ,D,R,E,A,M,0};
printf(%s,str);
}
Output:
I HAVE A DREAM
: )\ 0 " " (
#include <stdio.h>
int main()
{
char str*20+= I HAVE A DREAM;
printf(%s,str);
}
Output:
I HAVE A DREAM

Avshalom Elmalech 83-120

:
#include <stdio.h>
int main()
{
char str[20];
str*0+ = I;
str*1+ = ;
str*2+ = H;
str*3+ = A;
str*4+ = V;
str*5+ = E;
str*6+ = ;
str*7+ = A;
str*8+ = ;
str*9+ = D;
str*10+ = R;
str*11+ = E;
str*12+ = A;
str*13+ = M;
str*14+ = \0;
printf(%s,str);
}
Output :
I HAVE A DREAM

Avshalom Elmalech 83-120

:
, GETCHAR " :
)// ( . %S , SCANF " :
, STR , GETS(STR) :
.
#include <stdio.h>
#define MAX_SIZE 50
//This program replace * to _
int main()
{
int index;
char str[MAX_SIZE];
printf(Enter text: );
scanf(%s, str); // String input
//using getchar() function instead of scanf()
/*************************
do
{
str[i]=getchar();
i++;
}while(str[i-1]!='\n');
str[i-1]='\0';

**************************/
for(index=0; str*index+!=\0; index++)
if (str[index]=='*')
str*index+=_;
printf(The new text is: %s\n ,str);
}
Output :
Enter text:
567ehcyd*hdfyg8*** 43 $%#@*)
The new text is:
567ehcyd_hdfyg8___ 43 $%#@_)
?
, PUTCHAR " :
) /0 ( . %S , PRINTF " :
PRINTF , STR PUTS(STR) " :

Avshalom Elmalech 83-120

: , STRLEN

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 50
int main()
{
char str[MAX_SIZE];
int index=0,i=0;
printf("Enter text: ");
do
{
str[i]=getchar();
i++;
}while(str[i-1]!='\n');
str[i-1]='\0';
//counts how many characters in the string.
while(str[index]!='\0')
index++;
printf("The length of the string is: %d\n",index);
printf("The length of the string is %d\n",strlen(str));
}

: STRCPY
#include <stdio.h>
int main()
{
char name1*10+=copy;
char name2[10];
name2 = name1; //error
name2= coffee; // error, can be done only in initialization
return 0;
}
?
..... , :
.... :
#include <stdio.h>
#include <string.h>
//copy one string to another.
Avshalom Elmalech 83-120

int main()
{
char name1*10+=source;
char name2[10];
strcpy(name2,name1); // dest source
printf(%s\n,name2);
}
:
? 2
:'
STRCMP :'
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 50
int main()
{
char str1[MAX_SIZE];
char str2[MAX_SIZE];
char str3[MAX_SIZE];
printf(Enter text: );
scanf(%s,str1);
printf(The length of the string is: %d \n,
strlen(str1));
strcpy(str2,str1);
printf( Duplicated string: %s\n,str2);
printf(Enter another string: );
scanf(%s,str3);
if(strcmp(str1,str3)==0)
printf(The strings are identical\n);
else
printf(The strings are different\n);
}

Avshalom Elmalech 83-120

You might also like