c programming answers for chapter 6

35
ררררר ררררר רררר6 ררררר ררררC רררררררר- ווו וווו: ו"ו ווווו וווו1 . וווווווו וווווו ווווו ווווו ווו וווווו ווווו ווו וווו וווו ווווו וווו- וו וווו וווווו רר וווו ווו ררר.2 . ווווו וווווו ווווווו וווווו וווו וו ווווווו, וווו וווו וו ווווו ווווווו ווווווו. וווו וווו ווו, וווו וו3 . וווו וווווו וווווווו ווווו וווו וו וווווו ווווו ווו וווווו- ווווו וlinking ווו ווווווו- . וווו וווווו ווווווווו וווווו וו ווווו, וווו ווווווC Runtime Libraries . ררררר רררררר רר ררררררר: ווווווו וו וווווווו =( וווווfunction prototype :) (; return-type function-name)arguments declaration ווווו:return-type function-name)arguments( {function body} וווו וווווו וווווווו וווווו וווווו וו וווווו וו וווווווו! ררר ררררר:void/non-void type ררררר ררררררררר: וווווו וו וווווווו וווווווווו ווווווו וווווווו וווווווווו וווו וווווווו ווווו וו וווווווווו ווו. וווו וווו ווווו וו וווווווו וווווווווו!!! ווווו1 וווו וווווו וווווו ווווווו וווו וווווווו וווווו ווו וווווו וו ווווווו וו ווו- וווווו וו וווו וווו. וו ווווו1 , ווווווו ווווו וו ווו- וווווו ו- 1 ווו ווווו וווו ווו, וו ווווו2 וווווו ווווווו ווווו2 וו ווווו. וווווו וו ווווו0 . וו ווווו וו ווווווו ווווווו וווווווו ווווווו וו וווו וווווו. #include <stdio.h> #include<conio.h> int func_odd)int n ,int k( וווו1 וווו35 Formal parameters

Upload: sce

Post on 20-Apr-2023

0 views

Category:

Documents


0 download

TRANSCRIPT

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

וווווווו וווווו ווווו ווווו ווו וווווו ווווו ווו וווו וווו.1ררר. וווו ווו ררוו וווו וווווו - ווווו וווו

ווווו וווווו ווווווו וווווו וווו וו ווווווו, וווו וווו וו.2וווו וווו ווו, וווו וו ווווו ווווווו ווווווו.

וווו וווווו וווווווו ווווו וווו וו וווווו ווווו ווו וווווו.3. וווו וווווו ווווווווו וווווו וו-ווו וווווווlinkingווווו ו-

.C Runtime Librariesווווו, וווו וווווו

:ררררר רררררר רר ררררררר = ווווווו וו וווווווו( וווווfunction prototype:)

(; return-type function-name)arguments declaration

:ווווו return-type function-name)arguments(

{function body}

וווו וווווו וווווווו וווווו וווווו וו וווווו וו וווווווו!

void/non-void type ררר ררררר:

ררררר ררררררררר:וווווו וו וווווווו וווווווווו ווווווו וווווווו וווווווווו וווווווווווו ווווו וו וווווווווו ווו. וווו וווו ווווו וו וווווווו

וווווווווו!!!

וווו וווווו וווווו ווווווו וווו וווווווו וווווו ווו – 1ווווו ,1וו ווווו . וווווו וו וווו וווו-וווווו וו ווווווו וו ווו

2וו ווווו , ווו ווווו וווו ווו1-וווווו ו-ווווווו ווווו וו ווו וו ווווו.0 וו ווווו. וווווו וו ווווו 2וווווו ווווווו ווווו

.וו ווווווו ווווווו וווווווו ווווווו וו וווו וווווו#include <stdio.h>#include<conio.h>int func_odd)int n ,int k(

35 וווו 1 וווו

Formalparameters

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{int i;printf)"You choose to print odd numbers from 1 to %d\

n",n(;for)i=k;i<=n;i+=2(

printf)"%4d",i(;}

int func_even)int n, int k({

int i;printf)"You choose to print even numbers from 2 to %d\n",n(;

for)i=k;i<=n;i+=2(printf)"%4d",i(;

}int main)({int i, num, kind;printf)"Please enter a number for upper border\n"(; scanf)"%d",&num(;printf)"what kind of numbers would you like?\n1 is for odd numbers,\n2 is for even,\n0 to exit:\n"(;scanf)"%d",&kind(;switch )kind({case 1: func_odd)num,kind(;

break; case 2: func_even)num,kind(;

break;case 0: printf)"You choose to EXIT the PROGRAM !!! %d\n"(;

break;default: printf)"You choose wrong number !!!\n"(;

break;}getch)(;main)(;}

35 וווו 2 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

1-וו 'וווו וווווו וווווו וווו ווווו וווווווווו ווווו – 2ווווו forווווווו וווו וו ווווו ווווו ווווו ווווו וו ווווו . 10- ו

1וווווו וווו וווווו וו וווווו . while וווווו do whileווווו 0, וווו וווו וווו'וו ווווווווו2, וו'וווו וווו ווווווווו ווווו

.וווווו וווווווו.וו וווו וו ווווווו ווווווו וווווווו וווו

#include <stdio.h>int centimeter_to_inch)({

int i;printf)"You choose to convert centimeter to inches\n"(;

printf)"In For loop!!!\n"(;printf)"Centimeters\inches\n"(;for)i=1;i<=10;i++(

printf)"%d\t\t%.3f\n",i,i*2.54 (;i=1;printf)"\nIn While loop!!!\n"(;printf)"Centimeter\t Inches\n"(;while )i<=10(

{printf)"%d\t\t%.3f\n",i,i*2.54 (;

i++;}

i=1;printf)"\nIn Do While loop!!!\n"(;printf)"Centimeters\inches\n"(;do

{printf)"%d\t\t%.3f\n",i,i*2.54 (;

i++;}

while )i<=10(; }int inch_to_centimeter)({

int i;printf)"You choose to convert from centimeter to inches\n"(;

printf)"In For loop!!!\n"(;printf)"Inches\centimeter\n"(;

35 וווו 3 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

for)i=1;i<=10;i++(printf)"%d\t%.3f\n",i,i/2.54 (;

i=1;printf)"\nIn While loop!!!\n"(;printf)"Inches\centimeter\n"(;while )i<=10(

{printf)"%d\t%.3f\n",i,i/2.54 (;i++;}

i=1;printf)"\nIn Do While loop!!!\n"(;printf)"Inches\centimeter\n"(;do

{printf)"%d\t%.3f\n",i,i/2.54 (;i++;}

while )i<=10(;}int main)({int i, num=10, kind;printf)"what kind of conversion?\n"(;printf)"1 from centimeter to inch\n"(;printf)"2 from inch to centimeter, 0 to exit\n"(;scanf)"%d",&kind(;switch )kind({case 1:

centimeter_to_inch)(;break;case 2:

inch_to_centimeter)(;break;case 0:

printf)"You choose to EXIT the PROGRAM !!!\n"(;break;}getch)(;

35 וווו 4 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

}

וווווווו ווווו6 - וווו וווווו וווווו וווו וווווו 3ווווו ווווו ווווווו:

וווו ו' ווווווו ווווווו ווווו וווו:

*

**

***

****

*****

וווו ו' - וווו ווווווו ווווווו ווווו וווו וווו:

***************

וווו ו' - וווו ווווווו ווווווו ווווו וווו:

* **

***

****

*****

וווו ו' - וווו ווווווו ווווווו ווווו וווו וווו:

*****

35 וווו 5 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

**********

וווו ו' - וווו ווווווו ווווווו ווווו וווו ווווו ווו:

*********

***************************

וווו ו' - וווו ווווווו ווווווו ווווו וווו ווווו וווו:

************************************

-3ווווו ווווו וווו #include <stdio.h>#include<conio.h>void tr1)int r({

int i,j;for)i=1; i<=r; i++({for)j=1; j<=i; j++(

printf)"*"(;printf)"\n"(;}

}

35 וווו 6 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

void tr2)int r({

int i,j;for)i=1; i<=r; i++({for)j=r; j>=i; j--(

printf)"*"(;printf)"\n"(;

}}

void tr3)int r({

int i,j,k,space=r-1;for)i=1; i<=r; i++({for)k=space; k>=1; k--(

printf)" "(;for)j=1; j<=i; j++(

printf)"*"(;printf)"\n"(;space--;

}}

void tr4)int r({

int i,j,k,space=0;for)i=1; i<=r; i++({for)k=1; k<=space; k++(

printf)" "(;for)j=r; j>=i; j--(

printf)"*"(;printf)"\n"(;space++;}

}

void tr5)int r(35 וווו 7 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{int i,j,k,space=r-1;for)i=1; i<=r; i++({for)k=space; k>=1; k--(

printf)" "(;for)j=1; j<=i*2-1; j++(

printf)"*"(;printf)"\n"(;space--;}

}

void tr6)int r({

int i,j,k,space=0;for)i=1; i<=r; i++({for)k=1; k<=space; k++(

printf)" "(;for)j=r*2; j>=i*2; j--(

printf)"*"(;printf)"\n"(;space++;}

}

int main)({int i,j,rows,kind;printf)"Enter number of rows:\n"(;scanf)"%d",&rows(;printf)"For TR1 enter 1\n"(;printf)"For TR2 enter 2\n"(;printf)"For TR3 enter 3\n"(;printf)"For TR4 enter 4\n"(;printf)"For TR5 enter 5\n"(;printf)"For TR6 enter 6\n"(;printf)"Enter number TR\n"(;scanf)"%d",&kind(;

35 וווו 8 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

switch)kind({case 1:

tr1)rows(;break;

case 2:tr2)rows(;break;

case 3:tr3)rows(;break;

case 4:tr4)rows(;break;

case 5:tr5)rows(;break;

case 6:tr6)rows(;break;

default:break;

}main)(;getch)(;}

.וווו ווווווו וווווו וווו וווווו וו ווווו ווו - 4ווווו #include<stdio.h>int factorial )int n({int result = 1, i;for )i = 1; i <= n; ++i(

result *= i;return result;}int main)(

35 וווו 9 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{int number;printf)"Enter your number:\n"(;scanf)"%d",&number(;printf)"The factorial of %d is %d\n",number,factorial )number((;return 0 ;}

.וווו ווווווו וווווו ווו וווווו ווווו ווו ווווו וווו - 5ווווו #include<stdio.h>int power)int a, int b({int result = 1, i;for )i = 1; i <= b; ++i(

result *= a;return result;}int main)({int num1,num2;printf)"Enter 2 numbers:\n"(;scanf)"%d %d",&num1,&num2(;printf)"%d power %d is %d!\n",num1,num2,power)num1,num2((;return 0 ;}

- ווווווו וו ווווו וnוווו ווווווו וווווו וווו וווו - 6ווווו nו' ווווו וווווו.

35 וווו 10 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

#include<stdio.h>int fib)int n({int num1 = 0, num2 = 1, cur=0, cur_index = 1;if )n < 2(

return n;while )cur_index < n({

cur = num1+num2;num1 = num2;num2 = cur;cur_index++;printf)"%4d",cur(;

}return cur;}int main)({int number;printf)"Enter number in fib list:\n"(;scanf)"%d",&number(;printf)"num %d in fib list is %d\n",number,fib)number((;return 0 ;}

וו, וו ווו וווווו1וווו ווווווו וווווו וווו ווווווו - 7ווווו . וו וו0

#include<stdio.h>int prime)int n({int i;for )i = 2; i < n; i++({ if )n % i == 0(

35 וווו 11 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

return 0;}return 1;}int main)({

int number;printf)"Enter your number for prime check:\n"(;scanf)"%d",&number(;if)prime)number( == 1(

printf)"The number %d is prime!!!\n",number(;else

printf)"The number %d is not prime!!!\n",number(;return 0 ;

}

.וווו ווווווו ווווווו וו ווו וווו וו וווו - 8ווווו #include<stdio.h>int kefel)int N({int i, j;for )j = 1; j <= N; j++({

for )i = 1; i <= N; i++( printf)"%5d", i*j(;

putchar)'\n'(;}}int main)({int number;printf)"Enter number in table:\n"(;scanf)"%d",&number(;kefel)number(;

35 וווו 12 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

return 0 ;}

,unsigned long וווו xוווו ווווווו וווווו וווו - 9 ווווו.iווווו ווו וווו

.x ווווו ווווו I- וווווווו ווווו וו ווווו ו#include<stdio.h>int get_digit)unsigned long x, int i({int counter;for )counter = 1; counter < i; counter++(

x /= 10;return x % 10;}int main)({

unsigned long number1,number2;printf)"Enter unsigned long number and other number for\

n"(;scanf)"%ld %d",&number1, &number2(;printf)"Number %d place %d right digit is %d.\

n",number1,number2,get_digit)number1,number2((;return 0;

}

ווווווunsigned longוווו ווווווו וווווו וווו וווו - 10ווווו .וו וווו ווווווו

#include<stdio.h>unsigned long count)unsigned long N({unsigned long c=0;while)N>0({

N=N/10;c++;

}

35 וווו 13 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

return c;}int main)({unsigned long number;printf)"Enter unsigned long number\n"(;scanf)"%ld",&number(;printf)"%d digits count is %d.\n",number,count)number((;return 0;}

ווווווunsigned longוווו ווווווו וווווו וווו וווו - 11ווווו .וו וווו ווווווו

#include<stdio.h>unsigned long sum)unsigned long N({unsigned long s=0;while)N>0({

s=s+N%10;N=N/10;

}return s;}int main)({unsigned long number;printf)"Enter unsigned long number\n"(;scanf)"%ld",&number(;printf)"%d sum digits is %d.\n",number,sum)number((;return 0;}

35 וווו 14 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

-2 , 1: וווו ווווווו ווווווו וו ווווו וווו וו וווו - 12ווווו ,3 , 4 , -5 , 6 , … , -9 , 10-

#include<stdio.h>void print_zigzag)({int i = 1, negative = -1;for )i = 10; i >= 1; i--({printf)"%d\t", i*negative(;negative *= -1;}}int main)({

print_zigzag)(;return 0;

}

וווו ווווווו וווווו ווווו וו וווווו וו וווווו - 13ווווו ,וווווו ווווו וווווווו ווווווו וו וווווו 1-וווווווו ווווו

.וווו ווווו וו וו וווו#include <stdio.h>void swap)int *a, int *b({int temp = *a;*a = *b;*b = temp;}int main)({int n1, n2,check;printf)"Enter 2 numbers:\n"(;scanf)"%d %d",&n1, &n2(;if )n1 > n2(

35 וווו 15 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

swap)&n1, &n2(;while)scanf)"%d",&check( == 1 && check != -1({if )check > 0({

if )n2 < 0( n2 = check;

else if )n1 < 0(

n1 = check;else

if )check < n1({n2 = n1;n1 = check;}

elseif )check < n2(

n2 = check;}

}printf)"%d %d\n", n1, n2(;return 0;}

וווווunsigned long וווו xוווו ווווווו וווווו וווו - 14ווווו . x ווווו ווווו i- ווווווו וו ווווו וIוווו

#include<stdio.h>int digits_number)unsigned long x({int counter = 0;while )x > 0({counter++;x /= 10;

35 וווו 16 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

}return counter;}

int get_digit)unsigned long x, int i({int n, x_length = digits_number)x(;for )n = 0; n < x_length - i; ++n({x /= 10;}return x % 10;}

int main)({unsigned long number1,number2;printf)"Enter unsigned long number and other number for\n"(;scanf)"%ld %d",&number1, &number2(;printf)"Number %d place %d left digit is %d.\n",number1,number2,get_digit)number1,number2((;return 0;}

12 ווווווו וו ווווו nוווו ווווווו וווווו ווו ווו – 15ווווו ...n

int sum1)int n(//Alef-can be converted to n/2+n^2/2{if )n <= 0( return 0;int s = n;while )--n(

s+=n;return s;}int sum2)int k(//Bet-sum of )j+1()k-j( for j from 0 to k-1

35 וווו 17 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{int s = 0;int j;for )j=0;j<k;++j(

s += sum1)j+1(;//sum1)j+1(-same as )j+1()k-j(return s;}

- וווו ווווווו וווווו וווו וווווו ווו ווו וווווו. וווו16ווווו ווו וווווווו ווו ווווו100 ו- 2וווווו ווווו וו וו ווווווו ווו

וווווווו.#include <stdio.h>int prime)int n({int i;for )i = 2; i < n; i++(

{if )n % i == 0(

return 0;}

return 1;}int main )({int i;printf)"The prime numbers from 1 to 100 are:\n"(;for )i = 1; i <=100; i++(

if )prime)i(==1(printf)"%d\t",i(;

35 וווו 18 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

return 0;}

- וווו וווווו וווווו ווווו ווווווו וווווווו ווווו17ווווו ווווווו.

#include <stdio.h>float celsius_to_fahrenheit)int celsius({return )1.8 * celsius( + 32;} int main)({int celsius, fahrenheit;for )celsius = 1; celsius <= 40; celsius += 2( printf)" %d\t in Celsius is %2.f in Fahrenheit\n", celsius,celsius_to_fahrenheit)celsius((;printf)"Enter degrees in Clesius: "(; scanf)" %d", &celsius(;printf)"This is %2.f in Fahrenheit.\n", celsius_to_fahrenheit)celsius((;return 0;}

וווווו ווו וווווו ווווו, וווווווmax - וווו ווווווו 18ווווו 10ווו וו וווווווו ווווווו וווווו וו ווו ווווו וווו וווווו.

ווווו וו וווווו.#include <stdio.h>int max)int a, int b({

if)a > b( return a;else return b;

}int main )(

35 וווו 19 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{int i,a,b;printf)"Enter 10 peers of numbers:\n"(;for )i = 1; i <=10; i++(

{printf)"Round number %d\n",i(;scanf)"%d%d",&a,&b(;printf)"The max number is: %d\t\n",max)a,b((;}

return 0;}

- וווו ווווווו וווו – וווו ווווווו וווווו וווו ווו19ווווו !, n, ווווו וו nוווווו !n. ווו וו וווווווו ווווווו וווווו וו n * ... * 2 * 1ווווו

.10 וו 1ווווווו #include <stdio.h>unsigned long factorial)unsigned int n({unsigned long fact = 1; unsigned int i;for)i = 1; i <= n; ++i(

fact *= i;return fact;}void main )({int i; printf)"The !n of the numbers 1 to 7:\n"(;for )i = 1; i <=10; i++(

printf)"Factorial of %d\t is: %d\n",i,factorial)i((;}

- וווו ווווווו ווו ווווו וווו ווווווו ווווו וו @20ווווו ווווווו ווווווו וווווווו.

35 וווו 20 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

וווו וו וווו ווו:5וווווו וווו ווווו ווווו @ @ @ @ @

@ @ @ @ @ @ @ @ @ @ @ @ @ @ @

@ @ @ @ @#include <stdio.h>int tav)int n({int i,j;{ printf)"The matrix of @:\n"(; for )i = 1; i <= n; i++( { for )j = 1; j <= n; j++(

printf)" @ "(; printf)"\n"(; }}return 0;}void main)({int n; printf)"Enter number for nXn: "(;scanf)"%d",&n(; tav)n(; }

וו וווווו ווווו וווו ררוו ווווו וו וווווווו וווווו וו ווווווווווו ווווו וווווו.

#include <stdio.h>int tav)char num, char ch({

35 וווו 21 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

int i,j;{ printf)"The matrix:\n"(; for )i = 1; i <= num; i++( { for )j = 1; j <= num; j++( printf)"\t%c\t",ch(; printf)"\n"(; }}

וווווו ווווווו וווווווו וווו3 - וווו וווווו וווווו 21ווווו unsigned long.וווווו וו ווו ווווו ווווווו

ווווווו ווווו ווווווו וו וווו וו ווווווו וו וו וווו ווווו וווווו ווווו וווווווו ווווו ווו וווו וו וווו וווווו.

#include <stdio.h>

int sum_digit)unsigned long num({int sum = 0;

while )num > 0({sum += num % 10;num /= 10;}

return sum;}

int digits_number)unsigned long num({int counter = 0;

while )num > 0({counter++;

35 וווו 22 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

num /= 10;}

return counter;}

void main)({int i;unsigned long num=0;printf)"Enter 3 numbers, each number digits will be sumed and digit number will print.\n"(;for )i = 1; i <= 3; i++({printf)"Enter number %d out of 10\n",i(;scanf)"%ld",&num(;printf)"Sum of number digit is: %d\n",sum_digit)num((;printf)"Number of digits in the number is: %d\n",digits_number)num((;}}

וווווו וווווו ווווווו2 - וו ווווו וווווו וווווו 22ווווו ווווווו וו ווווו ווווו:

ווווו ווו ווווווו..1ווווו ווו ווווווו..2ווו ווו ווווווו..3ווווו ווו ווווווו..4

וו ווו וווווווו ווווו ו"ו ווווווו ווווו וו ווו ווווווו וווווווווווו וו וווווו.

.switch-caseוו וווווו וווווו וו וווו ווווו #include <stdio.h>float hibur_numbers)float mis1, float mis2({float sum = mis1 + mis2; return sum;}

35 וווו 23 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

float hisur_numbers)float mis1, float mis2({float sum = mis1 - mis2; return sum;}

float kefel_numbers)float mis1, float mis2({float sum = mis1 * mis2; return sum;}

float hiluk_numbers)float mis1, float mis2({float sum = mis1 / mis2; return sum;}

void main)({int ch,i;float mis1,mis2;printf)"Two numbers Calculator\n"(;printf)"=================\n"(;for )i=1;i<=4;i++({

printf)"Enter first number:\n"(;scanf)"%f",&mis1(;printf)"Enter second number:\n"(;scanf)"%f",&mis2(;printf)"Choose:\n1 for hibur.\n2 for hisur.\n3 for kefel.\n4

for hiluk.\n"(;scanf)"%d",&ch(;switch )ch({case )1(:

printf)"%.3f+%.3f=%.3f\n",mis1,mis2,hibur_numbers)mis1, mis2((;break;

case )2(: printf)"%.3f-%.3f=%.3f\n",mis1,mis2,hisur_numbers)mis1, mis2((;

break;case )3(:

35 וווו 24 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

printf)"%.3f*%.3f=%.3f\n",mis1,mis2,kefel_numbers)mis1, mis2((;break;

case )4(: printf)"%.3f/%.3f=%.3f\n",mis1,mis2,hiluk_numbers)mis1, mis2((;

break;default:

printf)"You enterd incorrect number !!!"(;}

}}

- וווו ווווווו ווווווו וו וווו ווווו ווווווו ווווו וו23ווווו ווווווו וווווו. Nוווווו ווווו

int diagonal)int matrix[n][n]({int i, j, sum=0;for)i = 0; i < n; ++i({ for)j = 0; j < n; ++j( {

if )i==j({sum=sum+matrix[i][j];printf)"The Matrix main diagonal number %d\t", matrix[i][j](;printf)"\n"(;}

}}return sum;}

- וווו ווווווו וווווו וווו ווו ווווו, וווווווו ווווו24ווווו וו ווו ווווווו וו ווווו וווווו.

#define N 10typedef int mat[N][N];

35 וווו 25 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

int sum_matrix)mat m({int i, sum = 0;for )i = 0; i < N; ++i(

sum += m[i][i];return sum;}

N, וווו N xN - וווו ווווווו וווווו וווו וו וווו ווווו 25ווווו וווו.0 וווווו 0 וו ווווו וווו וו 1ווו וווו, וווווווו ווווו

int only_zeros)int mat[N][M]({int i, j;for )i = 0; i < N; ++i({

for )j = 0; j < M; ++j({if )mat[i][j] != 0(

return 0;}

}return 1;}

- וווו ווווווו וווווו וווו וו וווו ווווו 26ווווו N וו Nוווווו ווו וווווו וווו וווו, וו ווווווו וו ווווו וווווווו

וווווו ווווו וווווו, ווווווו ווווווו ווווו.

void print_reverese_odd)int mat[N][M]({int i, j;for )i = 0; i < N; ++i({

for )j = 0; j < M; ++j(

35 וווו 26 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

{if )i % 2 == 0(

printf)"%d\t", mat[i][j](;else

printf)"%d\t", mat[i][M-1-j](;}

}}

וו ווTRUE – וווו ווווווו וווווו וווו וווווו ווווווו 27ווווו .FALSEווווו ווו וווווו ווווו ווווו וווו וווווו

#define TRUE 1#define FALSE 0int two_equals)int* arr, int n({int counter;merge_sort)arr, n(;for )counter = 0; counter < n - 1; ++counter(if )arr[counter] == arr[counter+1](

return TRUE;return FALSE;}

- וווו וווווו וווווו ווו וו ווווו28ווווו #include<stdio.h>#include<math.h> #define M_PI 3.14int main)( { int s1, s2, angle; float area; printf)"\nEnter Side1 : "(; scanf)"%d", &s1(;

35 וווו 27 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

printf)"\nEnter Side2 : "(; scanf)"%d", &s2(; printf)"\nEnter included angle : "(; scanf)"%d", &angle(; area = )s1 * s2 * sin))M_PI / 180( * angle(( / 2; printf)"\nArea of Scalene Triangle : %.2f\n", area(; return )0(;{

- וווו וווווו וווווו ווווו וווו וווווו29ווווו #include<stdio.h>#include<math.h> int main)( { int side; float area, r_4; r_4 = sqrt)3.( / 4; printf)"\nEnter the Length of Side : "(; scanf)"%d", &side(; area = r_4 * side * side; printf)"\nArea of Equilateral Triangle : %.2f\n", area(; return )0(;}

- וווו וווווו וווווו וווווו ווווווו30ווווו #include<stdio.h>#include<math.h>int main)( { float a, b, c;

35 וווו 28 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

float desc, root1, root2; printf)"\nEnter the Values of a : "(; scanf)"%f", &a(; printf)"\nEnter the Values of b : "(; scanf)"%f", &b(; printf)"\nEnter the Values of c : "(; scanf)"%f", &c(; desc = sqrt)b * b - 4 * a * c(; root1 = )-b + desc( / )2.0 * a(; root2 = )-b - desc( / )2.0 * a(; printf)"\nFirst Root : %.2f", root1(; printf)"\nSecond Root : %.2f\n", root2(; return )0(;{

וווו וווווו וווווו ווו וווו וווו וווווו וווו ווו וו - 31ווווו .וו וווווו וווו וווווו, ווווו

#include<stdio.h>#include<conio.h>#include<math.h> int fm)int date, int month, int year( { int fmonth, leap; //leap function 1 for leap & 0 for non-leap if ))year % 100 == 0( && )year % 400 != 0(( leap = 0; else if )year % 4 == 0( leap = 1; else leap = 0;

35 וווו 29 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

fmonth = 3 + )2 - leap( * ))month + 2( / )2 * month(( + )5 * month + month / 9( / 2; //bring it in range of 0 to 6 fmonth = fmonth % 7; return fmonth;} //----------------------------------------------int day_of_week)int date, int month, int year( { int dayOfWeek; int YY = year % 100; int century = year / 100; printf)"\nDate: %d/%d/%d \n", date, month, year(; dayOfWeek = 1.25 * YY + fm)date, month, year( + date - 2 * )century % 4(; //remainder on division by 7 dayOfWeek = dayOfWeek % 7; switch )dayOfWeek( { case 0: printf)"weekday = Saturday\n"(; break; case 1: printf)"weekday = Sunday\n"(; break; case 2: printf)"weekday = Monday\n"(; break; case 3: printf)"weekday = Tuesday\n"(; break; case 4: printf)"weekday = Wednesday\n"(; break;

35 וווו 30 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

case 5: printf)"weekday = Thursday\n"(; break; case 6: printf)"weekday = Friday\n"(; break; default: printf)"Incorrect data\n"(; } return 0;}//------------------------------------------int main)( { int date, month, year; printf)"\nEnter the year "(; scanf)"%d", &year(; printf)"\nEnter the month "(; scanf)"%d", &month(; printf)"\nEnter the date "(; scanf)"%d", &date(; day_of_week)date, month, year(; return 0;{

. וווו וווווו וווווו ווו וווו ווו וווו ווווווווו –32ווווו ווווו ווווו ווווו ווווווו וווו n וווו ווווווווו ווו וווו ווו

n. וו ווו ווו וווווו ווווו

35 וווו 31 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

8208, 1634, 407, 371, 370, 153 וווווו וווווו: 370 = 03 + 73 + 33  ווו וווו ווווווווו וווו ו-370

#include<stdio.h>#include<math.h>int main)( { int num, temp, sum = 0, rem; printf)"\nEnter number for checking Armstrong: "(; scanf)"%d", &num(; temp = num; while )num != 0( { rem = num % 10; sum = sum + pow))float(rem,3(; num = num / 10; } if )temp == sum( printf)"%d is Armstrong Number!!!\n", temp(; else printf)"%d is not Armstrong Number!!!\n", temp(; return )0(;{

3וווו ווווווו ווו וווווו וו ווווו ווווו ווווו וווו - 33ווווו .וווווו וווו ווווו

#include <stdio.h>//Maximum from there variables int max)int , int , int (;

int main)({

int num1,num2,num3;

35 וווו 32 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

printf)"Enter 3 numbers:\n"(;//Input three int numbersscanf)"%d %d %d",&num1,&num2,&num3(;printf)"Maximum number: %d\n",max)num1,num2,num3((;

return 0;}int max)int mis1, int mis2, int mis3({

if))mis1 > mis2( && )mis1 > mis3((return mis1;

else if))mis2 > mis3( && )mis2 > mis1((

return mis2; else

return mis3;}

וווווו ווווו ווווווו 2וווו ווווווו ווו ווווו - 34ווווו .ווווווו וו ווווו וווווו ווווו וו וווו וווו

וווווו ווווו ווווווו ווווו ווווו וווו 2וווו וווווו ווו ווווו ווווו , ו ווווווו וו וווווו"ווווווו וווווו וו וווווווו וו

.ווווו וו וווו וו ווווווו וווווו ווווו ווווווPower)2,3( =>8

#include <stdio.h>//Power function mis1)case( by mis2)exponent(int power)int mis1, int mis2({

int i,result=1;for)i=0;i<mis2;i++(

result*=mis1;return result;

}int main)({

35 וווו 33 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

int num1,num2;printf)"Enter 2 numbers:\n"(;//Input two numbersscanf)"%d %d",&num1,&num2(;//Input checkingif))num1<0( || )num2<0((

printf)"One of the numbers is negative !!!\n"(;elseprintf)"Power mis1 by mis2 is => %d\n",power)num1,num2((;

return 0;}

וווו ווווווו ווו ווווו וווו ווו וווו ווווו וווווו - 35ווווו . וו ווווו וווווו ווו ווווו

. וווו וווווו ווו ווווו וווו ווו וווו ווווו ו ווווווו וו"ווווו ווווו וווו ווווווו וווווו וו וווווווו וו

וו ווווו וווווו ווו וווו ווווווו ווווו: וווווו ווווו וווו " .וו וווו"וווו ווו ווווו " וווו"

.ווווו ווווו וו וווו וו ווווווו וווווו ווווו וווווו,וווו

CountDigits )123( =>"odd "CountDigits )1234( => "even"CountDigits )-123( => "Invalidate input"

#include <stdio.h>//Counter numbers digits functionint digits_number)long num({

int counter = 0;//Checking numberif)num<0({

35 וווו 34 וווו

6 ררררר ררררר רררר - רררררררר C ררררר רררר

ווו וווו: ו"ו ווווו וווו

printf)"Invalidate input !!!\n"(;retrun 0;

}while )num > 0({

counter++;num /= 10;

}return counter;

}int main)({

long num=0;printf)"Enter number\n"(;//Input long numberscanf)"%d",&num(;//Execute function if number is O.K.if)digits_number)num( % 2 == 0(printf)"Counter %ld digits==> even(\n",num,digits_number)num((;

elseprintf)"Counter %ld digits==> )odd(\n",num,digits_number)num((;return 0;

}

35 וווו 35 וווו