sheikh shibly nomany sporso publisher powered by … · sporso publisher powered by sporso group of...

46
SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected] 1 Short notes on C Programming 1. Write the structure of the C-Programming Language. #include<stdio.h> void main(){ ……. Statements; Statements; …….. } 2. Explain about increment or decrement operator. Ans: The symbol ‘++’ is known as increment operator that is by this operator the value of a variable can be increased by 1. The symbol ‘- -‘ is known as decrement operator that is by this operator the value of a variable can be decreased by 1. 3. Where can we use increment operator (++) or decrement operator (- -)? Ans: Before or after a variable we can use increment or decrement operator. Such as ++i, k- - where i and k are integer type of variable. 4. What do you mean by data types? Ans: The nature of data that is stored in the variable is called data types. 5. Classify and discuss about the data types of C-programming language. Ans: 6. Discuss about the conditional operator. Ans: The symbol “?:” is called conditional operator. We shall try to understand it by the following example. x ?: 7. Discuss about the logical operator. 8. Discuss about the short hand operator. 9. Write the difference between Operator and Operand. 10. What do you mean by Boolean expression? 11. What do you mean by control structure? 12. Write the difference between Structure and Union.

Upload: others

Post on 05-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

1

Short notes on C Programming

1. Write the structure of the C-Programming Language.

#include<stdio.h>

void main(){

…….

Statements;

Statements;

……..

}

2. Explain about increment or decrement operator.

Ans: The symbol ‘++’ is known as increment operator that is by this operator the value of a variable can be increased by 1. The symbol ‘- -‘ is known as decrement operator that is by this operator the value of a variable can be decreased by 1.

3. Where can we use increment operator (++) or decrement operator (- -)?

Ans: Before or after a variable we can use increment or decrement operator. Such as ++i, k- - where i and k are integer type of variable.

4. What do you mean by data types?

Ans: The nature of data that is stored in the variable is called data types.

5. Classify and discuss about the data types of C-programming language.

Ans:

6. Discuss about the conditional operator.

Ans: The symbol “?:” is called conditional operator. We shall try to understand it by the following example. x ?:

7. Discuss about the logical operator.

8. Discuss about the short hand operator.

9. Write the difference between Operator and Operand.

10. What do you mean by Boolean expression?

11. What do you mean by control structure?

12. Write the difference between Structure and Union.

Page 2: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

2

13. D

14. Write the difference between ‘ax++’ and ‘++ax’ where ‘ax’ is integer type of variable.

No The symbol ‘ax++’ The symbol ‘++ax’

1) The value of the variable will be incremented after taking part in the statement.

The value of the variable will be decremented before taking part in the statement.

15. What will be the output of the following program?

#include<stdio.h>

void main(){

int ax, bx, cx;

ax = 3;

bx = ax++;

printf(“%3d”,bx++);

printf(“%3d”,++bx);

printf(“%3d”,ax++);

}

16. How can you make difference a word from a function name in c-programming language?

Ans: After a c-programming function name a pair of parenthesis is existed but after a word or variables it does not existed.

17. Where from a c-programming codes are started to execute?

Ans: There may be more than one function in the c-programming language but always from the main() function, the statements or c-programming codes is started to execute.

18. How many main() function can be remain in c-programming language?

Ans: Only one main function can have in the c-programming language.

19. What is the name of the symbol “= “ ?

Ans: The name of the symbol of “= “ is assignment statement.

20. What do you mean by C-Tokens or key word or reserve word?

Page 3: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

3

Ans: There are some words in c-programming language whose activities or functions are known by c-compiler beforehand. These known words are known as C-Tokens or key word or reserved word. e.g. printf(), scanf(), int, float, getch() are C-Tokens.

21. What is the function of Assignment statement?

Ans: The function of assignment statement ( i.e. “=”) is to store the value of the right side variable to the left side variable.

DËit Assignment statement -Gi KvR nj, Wvb cv‡k¦©i †Kvb variable Gi †h‡Kv‡bv value evg cv‡k¦©i ‡Kvb variable -G Rgv Kiv|

22. What do you mean by statement?

Ans: a simple instruction or command to the computer which is used to do some thing by the computer is called statement.

DËit ‡h †QvÆ †QvÆ ûKzg Øviv Computer-†K w`‡q KvR Kiv‡bv nq Zv‡K statement e‡j|

23. ywU statement wKfv‡e Avjv`v Kiv nq?

Ans:We can separate two statements by a semicolon(;)

24. Where a semicolon can not be used?

Ans: if ev ‡h †Kvb loop – Gi c‡i semicolon(;) emv‡bv hv‡e bv|

25. What do you mean by string constant?

DËit ‡Kvb kã ev jvB‡bi yB cv‡k¦© Wej †Kv‡Ukb _vK‡j †mwU †K string constant wn‡m‡e aiv nq|

26. What do you mean by variable?

Ans: A memory space in the Hard disk where we can store a value. This value can be changed during programming execution.

27. What do you mean by constant?

Ans: A memory space in the Hard disk where we can store a value for one time and its value cannot be changed during programming execution. In other words a memory

Page 4: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

4

space whose value cannot be changed and remain constant during programming execution is called constant.

28. How can you give a name (bvg Ki‡Yi wbqg) of a variable?

Ans: (i) Only character, digit and underscore can be used.

(ii) Must start with a character.

(iii) Blank space is not allowed in the middle of a variable.

(iv) You can use maximum 8 characters.

(v) Reserved word or Key word must not be declared as a variable.

29. What do you mean by reserved words or key word?

Ans: There are some words which value is known by the C-Compiler from beforehand. These known words by the C-Compiler are called reserved word. Examples of reserved or key word are int, printf(), canf(), while, if, clrscr() etc.

30. What is the meaning of the statement “k = 3”?

Ans: k – Gi wfZi 3 Rgv n‡q hvI|

31. What is the function of printf() function?

DËit Bnvi gyj KvR nj gwbU‡i †Kvb Z_¨ †`Lv‡bv| Bnv wZb fv‡e †Kvb Z_¨ gwbU‡i †`Lv‡Z cv‡i| h_vt (i) String constant (ii) value of a variable (iii) String constant and value of a variable at the same time.

(i) String constant: printf() – Gi wfZi †Kvb kã e jvB‡bi yB cv‡k¦© †Kvb double quotation _vK‡j †m wU hv Av‡Q wVK AweKj ZvB monitor-G show K‡i| wKšZz

(ii) Value of a variable: ‡Kvb k‡ãi yB cv‡k¦© †Kvb double quotation bv _vK‡j †mwU variable wn‡m‡e a‡i Dnvi wfZ‡i †h value _‡K †mwU monitor-G show K‡i|

(iii) String constant + Value of a variable at the same time.

32. What will be the output of the following statement?

(i) printf(“I live in Bangladesh”); Output: I live in Bangladesh

(ii) suppose k = 3; printf(“%d”,k); Output: 3

Page 5: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

5

(iii) suppose p = 3; printf(“T = %d”,p); Output : T = 3

33. What is the function of scanf() function?

DËit Bnvi gyj KvR nj key board ‡_‡K †Kvb value c‡o ev scan K‡i scanf() - Gi parameter Gi wfZi store Kiv |

34. What is the meaning the following scanf() statement?scanf(“%d”,&abul) – Gi A_© nj †h value wU key board †_‡K †`Iqv n‡e †mwU Bnvi parameter variable (GLv‡b abul) Gi wfZi interger wn‡m‡e store Ki‡e|

(i) scanf(“%f”,&abul) – Gi A_© nj †h value wU key board †_‡K †`Iqv n‡e †mwU Bnvi parameter variable (GLv‡b abul) Gi wfZi float wn‡m‡e store Ki‡e|

35. What do you mean by control structure?

Ans: Normally the statements of the C program are executed one by one from left to right and top to down. In this case all the statements must be executed. But some time we may need to discard the execution of a specific statement. It is possible by the control structure.

In other words the structure by which we can take a decision whether a specific statement will be executed or not is called control structure.

Example of Control Structure: (i) if Structure (ii) Loop Structure

36. Describe the structure of the simple if statement.

Ans: The structure of the simple if statement is:

If( condition){

Statements1;

Statements2;

… … … ….

… … …. ….

Statements n

Page 6: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

6

}

Explanation: if – Gi conditional part wU mZ¨ n‡j if – Gi Body execute nB‡e Ab¨_vq if – Gi Body execute nB‡e bv|

37. Describe the structure of the compound if statement.

Ans: The structure of the simple if statement is:

If( condition){

Statements1;

Statements2; [true part]

… … … ….

… … …. ….

Statements n

}

else

{

Statements1;

Statements2; [false part]

… … … ….

… … …. ….

Statements n

}

Explaination: if – Gi conditional part wU mZ¨ n‡j if – Gi True Body A_©vr if – Gi cÖ_g Ask execute nB‡e Ab¨_vq if – Gi false Body A_©vr if – Gi wØZxq Ask execute nB‡e|

38. Write a program which will print the sentence “It is rainy season” after getting ‘1’ from key board and will print “It is summer season” after getting ‘2’ from key board.

#include<stdio.h> #include<conio.h> void main(){ int dada;

Page 7: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

7

printf("\nEnter a value form key board = "); scanf("%d",&dada); if(dada == 1) { printf("\nIt is rainy season"); } if(dada == 2) { printf("\nIt is summer season"); }

}

39. Write a program which can read an integer value from key board and test weather it is dividable by 5 or not ( 5 Øviv wefvR¨ wK bv Zv cix¶v Ki).

void main(){ int num,m; printf("\nEnter an inter vlaue ="); scanf("%d",&num); m = num%5; if(m == 0) { printf("\n%d is dividable by 5",num); } else { printf("\n%d is not dividable by 5",num); } }

40. ywU msL¨vi ¸bdj Ges Dnv‡`i GKwU input wn‡m‡e wb‡q Aci msL¨vwU †ei Ki|

#include<stdio.h> #include<conio.h> main(){ int total,one_num,sec_num; printf("\nGive the total number = "); scanf("%d",&total); printf("\nGive First number of them = "); scanf("%d",&one_num);

Page 8: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

8

sec_num = total/one_num; printf("\nThe seconde number is =%d",sec_num) ; }

41. GKwU msL¨v 40 †`Iqv Av‡Q| Dnv n‡Z KZ we‡qvM Ki‡j, msL¨vwU 7 Øviv wefvR¨ nB‡e ?

#include<stdio.h> #include<conio.h> main(){ int total,remender; total = 40; remender = total/7; printf("\nThe anser is = %d",remender); printf("\nMy name is Khan");

}

42. Write a program whose input and output are as follows:

input output

1 Saturday

2 Sunday

3 Monday

4 Tuesday

5 Wednesday

6 Thursday

7 Friday

Ans:

#include<stdio.h> #include<conio.h> main(){ int day_num; printf("\nInput the day number =" ); scanf("%d",&day_num); if(day_num == 1){

Page 9: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

9

printf("\nIt is Saturday"); } if(day_num == 2){ printf("\nIt is Sunday"); } if(day_num == 3){ printf("\nIt is Monday"); } if(day_num == 4){ printf("\nIt is Tuesday"); } if(day_num == 5){ printf("\nIt is Wednesday"); } if(day_num == 6){ printf("\nIt is Thursday"); } if(day_num == 7){ printf("\nIt is Friday"); }

}

43. miKvix wbqgvbymv‡i †Kvb Kg©Pvix evox fvov wbb¥wjwLZ QKvbymv‡i cvq| House rent †ei Kivi GKwU Program wjL|

g~j †eZb (Basic) kZKiv nvi (%) me©wbb¥ evox fvov

0 - 3000 60 % 1200

3001 - 6000 50% 2250

6000 †_‡K †ekx 40% 3250

#include<stdio.h> #include<conio.h> main(){ float basic, h_rent; printf("\nGive the amount of basic = "); scanf("%f",&basic); //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Page 10: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

10

if(basic >= 0 && basic <= 3000){ if(basic*0.60 < 1200) { h_rent = 1200; } else { h_rent = basic*0.6; } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& if(basic > 3000 && basic <= 6000){ if(basic*0.50 < 2250) { h_rent = 2250; } else { h_rent = basic*0.50; } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& if(basic > 6000){ if(basic*0.40 < 3250) { h_rent = 3250; } else { h_rent = basic*0.40; } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& printf("\nBasic:%5.2f\nHouseRent:%5.2f",basic,h_ rent); }

Page 11: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

11

44. Suppose if any one get 33 or greater than that then it will be treated as pass marks otherwise fail. Now, write a program that will get a number from key board and store it to a variable then justify that mark for fail or pass.

#include<stdio.h> #include<conio.h> main(){ int india; printf("\nGive a value = "); scanf("%d",&india); if(india >= 33 && india <= 100){ printf("\n%d is pass mark",india); } else { printf("\n%d is Fail Marik",india); } printf("\nHallow !! Hallow !!");

}

45. Write a program which can read an integer value from key board and test weather it is odd or even.

#include<stdio.h> #include<conio.h> void main(){ int num,m; printf("\nEnter an inter vlaue ="); scanf("%d",&num); m = num%2; if(m == 0) { printf("\n%d is Even"); } else { printf("\n%d is Odd"); } printf("\nGodd By!!");

Page 12: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

12

}

46. †Kvb GKRb e¨w³ PvKzix K‡ib| H e¨w³i g~j †eZb (basic) fvZvw` I KZ©bvw` input wn‡m‡e wb‡q †eZb wbb©q Ki| †eZ‡bi wbqg wbb¥iyc|

Allowance (cvIbv mg~n) Cutting (KZ©b mg~n)

1| g~j †eZb (wK †evW© n‡Z) 1| wc, Gd g~j †eZ‡bi 10 %

2| evox fvov g~j †eZ‡bi 40 % 2| Rxeb exgv KZ©b = 30 UvKv (wK †evW© n‡Z)

3| ‡gwW‡Kj = 700 UvKv (wK †evW© n‡Z) 3| K¬ve Puv`v = 20 UvKv (wK †evW© n‡Z)

4| †gvevBj = 300 UvKv (wK †evW© n‡Z) 4| ‡jvb KZ©b = 100 (wK †evW© n‡Z)

†gvU ‡eZb = KZ ?

#include<stdio.h> #include<conio.h> main(){ float basic, h_rent,total_sal,total_cut,pf_cut; float club_cut,insu_cut,loan_cut,salary; int medical,mobile; clrscr(); printf("\nGive the amount of basic = "); scanf("%f",&basic); printf("\nGive the amount of medical allowance = "); scanf("%d",&medical); printf("\nGive the amount of education allowance = "); scanf("%d",&mobile); printf("\nGive the amount of insurance cut = "); scanf("%f",&insu_cut); printf("\nGive amount of club contribution cut = "); scanf("%f",&club_cut); printf("\nGive the amount of Loan cut = "); scanf("%f",&loan_cut); h_rent = basic*0.40; pf_cut = basic*0.10; total_sal = basic + h_rent + medical + mobile; total_cut = pf_cut + insu_cut + club_cut + loan _cut; salary = total_sal - total_cut;

Page 13: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

13

printf("\nAll allowances:"); printf("\n Basic :%5.2f",basic); printf("\n House Rent:%5.2f",h_rent); printf("\n Medical :%5.2f",float(medical) ); printf("\n MobileBill:%5.2f",float(mobile)) ; printf("\n --------"); printf("\nTotal Allowance: %5.2f",total_sal); printf("\n\nAll cuttings:"); printf("\n PF :%5.2f",pf_cut); printf("\n Club :%5.2f",club_cut); printf("\n Insurance:%5.2f",insu_cut); printf("\n Loan cut :%5.2f",loan_cut); printf("\n ---------"); printf("\n Total cut = %5.2f",total_cut); printf("\n\n Payable Salary:%5.2f",salary); getch(); }

47. GK e¨w³ GKwU †`vKvb n‡Z wKQz cÖ‡qvRbxq wRwbm wKb‡jv Ges GKwU wbw ©ó As‡Ki †bvU H †`vKvbx‡K w`j| hvnv wbb¥ QKvbymv‡i †`Lv‡bv hvq| †`vKvb`vi Zv‡K KZ UvKv †diZ w`‡e? GLv‡b kZ© _v‡K †h, hw` wRwb‡mi `vg †`vK`vi‡K †`Iqv ‡bv‡Ui gv‡bi †P‡q †ekx n‡j, UvKv bv wb‡q ytL cÖKvk K‡i GKwU Lei cÖ k©b Ki‡e|

wRwb‡mi bvg UvKv

1| PvDj K‡qK †KwR 1| 50 UvKv A_ev (wK †evW© n‡Z)

2| wewfbœ cÖKvi gvQ 2| 70 UvKv A_ev (wK †evW© n‡Z)

3| gvsm 3| 80 UvKv A_ev (wK †evW© n‡Z)

4| wbw ©ó AsK gv‡bi UvKvi †bvU 4| 1000 UvKvi †bvU A_ev (wK †evW© n‡Z)

#include<stdio.h> #include<conio.h> main(){ float rice,meat,fish,value,back; int note; printf("\nGive the value of rice = "); scanf("%f",&rice);

Page 14: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

14

printf("\nGive the value of meat = "); scanf("%f",&meat); printf("\nGive the value of fish = "); scanf("%f",&fish); printf("\nGive the value of note = "); scanf("%d",&note); value = rice + meat + fish; if(float(note) < value){ printf("\nSorry !!"); printf("\n\nI am unable to receive money"); } else { back = float(note) - value; printf("\nThe amount of return money =%6.2f",b ack); } getch(); }

48. GK e¨w³ wKQz UvKv (20000) w¯¿ , yB(2) †Q‡j I wZb(3) Kb¨v †i‡L gviv †Mj| hw` Zvi w ¿ †gvU m¤úwËi 20%, cÖ‡Z¨K Kb¨v 10% Ges cÖ‡Z¨K cyÎ 25% K‡i UvKv cvq Zvn‡j, GLv‡b ejv †h‡Z cv‡i H e¨w³i UvKvi cwigvb 2000 UvKvi cwie‡Z© wK †evW© †_‡K †bIqv †h‡Z cv‡i|

(K) cÖ‡Z¨‡K KZ K‡i UvKv cv‡e ?

(L) GKRb cyÎ w¯¿ A‡c¶v KZ †ekx cv‡e ?

(M) GKRb cyÎ GKRb Kb¨v A‡c¶v KZ †ekx cv‡e ?

(N) wZb cyÎ GK‡Î †gvU KZ UvKv cv‡e ?

(O) yB Kb¨v GK‡Î ‡gvU KZ UvKv cv‡e ?

#include<stdio.h> #include<conio.h> main(){ int capital; float wife,son,daughter,tem; printf("\n\nGive the value of capital = "); scanf("%d",&capital);

Page 15: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

15

wife = capital*0.20; son = capital*0.25; daughter = capital*0.10; printf("\nThe money of the wife = %5.2f",wif e); printf("\nEach son's money = %5.2f",son); printf("\nEach daughter's money = %5.2f",daughte r); tem = son - wife; printf("\n\nSon's money more than wife = %5.2f", tem); tem = son - daughter; printf("\nSon's money more than daughter= %5.2f" ,tem); printf("\n\nTwo son's money = %5.2f",2*son); printf("\nThree daughter's money = %5.2f",3*daug hter); getch(); }

49. Write a program which can calculate letter grate point of a student after getting marks from key board.

#include<stdio.h> #include<conio.h> main(){ int marks,i; printf("\nGive your number = "); scanf("%d",&marks); if(marks<0 || marks >100){ printf("It is error number"); } if(marks >= 0 && marks < 33){ printf("The letter grade is = F"); } if(marks >= 33 && marks < 40){ printf("The letter grade is = D"); } if(marks >= 40 && marks < 50){ printf("The letter grade is = C"); } if(marks >= 50 && marks < 60){ printf("The letter grade is = B");

Page 16: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

16

} if(marks >= 60 && marks < 70){ printf("The letter grade is = A-"); } if(marks >= 70 && marks < 80){ printf("The letter grade is = A"); } if(marks >= 80 && marks <= 100){ printf("The letter grade is = A+"); } getch(); }

50. Write a program which can say which key you have pressed from the key board? [Suppose you can press any digit, character or functional key on the key board. After scanning that information the program has to say the category of key.]

wb‡Pi Program wU F7 w`‡q execute Kiv‡bv hvB‡e bv Ctrl+F9 execute Ki‡Z n‡e| Explain.

DËit F7 wb‡RB GKwU functional key hvi ASKEY value-Gi cª_g Ask 0. GB program wU F7 w`‡q execute Kiv‡bvi mgq Qó jvB‡b getch() Gi gva¨‡g ASKEY value-Gi cª_g Ask 0 co‡j Dnv num variable-Gi wfZi Rgv ev store nq hvnv mßg jvB‡bi while condition-‡K K‡i ‡`q| d‡j, compiler while loop - Gi body - ‡Z XzK‡Z cv‡i b| GKvi‡b Program wU F7 w`‡q execute Kiv‡bv hvB‡e bv

#include<stdio.h> #include<conio.h> void main(){ int num,m; printf("\nEnter an inter vlaue ="); num = getch(); while(num != 0){ printf("\nAskey = %d",num); num = getch(); } printf("\nGood by!!");

}

51. What can be done by the loop structure?

Page 17: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

17

Ans: A statement could be executed many times.

52. How many parts are there in the For-loop structure? Explain.

Ans: There are three parts in the For-loop structure. They are

1. initialization part;

2. conditional part;

3. increment part;

53. For-loop structure wK fv‡e KvR K‡i Zv wP‡Îi mvnv‡h¨ eY©bv Ki|

initialization ; Conditional part ; Increment ) {For(

}

Statement 1;

Statement 2;

-------

-------

-------

Statement n;

True

Out of the for loop

False

54. For loop e¨envi K‡i 5 †_‡K 20 ch©šZ we‡hvo msL¨v ¸wj wjL|

Ans:

#include<stdio.h> #include<conio.h> main(){ int k;

Page 18: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

18

for(k = 5; k<= 15; k = k+2){ printf("%4d",k); } getch(); }

55. While -loop structure wK fv‡e KvR K‡i Zv wP‡Îi mvnv‡h¨ eY©bv Ki|

DËit cÖ_‡g initialization part execute Ki‡e Zvici conditional part execute Ki‡e| hw` conditional part true nq Z‡e While loop – Gi Body -†Z XzK‡e Ges Body execute Kivi ci increment part – G †h‡q KvR K‡i cybivq conditional part – G cÖ‡ek Ki‡e| conditional part false n‡j Dnvi Body execute nB‡e bv|

Page 19: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

19

56. While loop e¨envi K‡i 5 †_‡K 20 ch©šZ we‡hvo msL¨v ¸wj wjL|

Ans:

#include<stdio.h> #include<conio.h> main(){ int k; k = 5; while(k <= 20){ printf("%4d",k); k = k + 2; } getch(); }

57. While loop e¨envi K‡i 100 †_‡K 1 ch©šZ we‡hvo msL¨v ¸wj wbb¥ µgvbymv‡i wjL|

#include<stdio.h> #include<conio.h> main(){ int k; k = 99; while(k >= 1){ printf("%4d",k); k = k - 2; } getch(); }

Dc‡iv³ program wU for – loop and do-while e¨envi K‡i m¤úv`b Ki|

58. Do - While -loop structure wK fv‡e KvR K‡i Zv wP‡Îi mvnv‡h¨ eY©bv Ki|

DËit cÖ_‡g initialization part execute Ki‡e Zvici ‡Kvb condition check QvovB Do - While -loop – Gi Body -†Z cÖ‡ek Ki‡e Ges increment part execute nIqvi ci Body ‡_‡K †ei n‡q conditional part execute Ki‡e| hw` conditional part true nq Z‡e Do - While loop – Gi Body -†Z cybivq XzK‡e| wKš‘ conditional part false n‡j Dnvi Body †Z wd‡i bv †h‡q Body Gi evwn‡i P‡j hv‡e| Ges Ab¨vb¨ statement execute Kiv ïiy Ki‡e|

Page 20: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

20

initialization ;

Do {

}

Statement 1;

Statement 2;

-------

-------

Statement n;

Increment part;

Out of the Do - While loop

False

Conditional part ) ;While(

True

59. Do – While - loop e¨envi K‡i 5 †_‡K 20 ch©šZ we‡hvo msL¨v ¸wj wjL|

Ans:

main(){

int kamal;

kamal = 1;

do {

printf(“%d”,kamal);

kamal = kamal +2;

} while (kamal <= 20)

}

60. Write the factors of a given number. (GKwU msL¨v BbcyU wn‡m‡e wb‡q, 1 †_‡K hZ¸wj msL¨v Øviv H msL¨v †K fvM Kiv hvq †mB msL¨v ¸wj evwni Ki|) | wb‡Pi programe wU whle-loop Ges do – while loop e¨envi K‡i wb‡R Ki|

#include<stdio.h>

Page 21: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

21

#include<conio.h> main(){ int num,i; printf("\nGive your number = "); scanf("%d",&num); for(i=1; i<= num; i++){ if( num % i == 0){ printf("%5d",i); } } getch(); }

61. Write the difference between While-Loop and Do-While Loop

While-Loop Do-While Loop

01 At first the conditional part is executed then if the conditional is true then the body the while-Loop will be executed

01 At last the conditional part is executed.

That is for the first time the body the Do-while-Loop will be executed without checking the condition.

02 If the conditional value is not true for the first time then the body of the While-Loop will be executed at all

02 Either true or false value of the conditional part, at least one time the body of the Do-While Loop must be executed

03 Draw the graph of the While-Loop 03 Draw the graph of the Do-While loop

62. Write a program which will take an integer number from key board and reverse it. (GKwU program wjL hvnv GKwU msL¨vi AsK ¸wj Dëv µ‡g †`Lv‡e|) †hgbt input 123 nB‡j output nB‡e 321| input 6234 nB‡j output nB‡e 4326| wb‡Pi programe wU do – while loop e¨envi K‡i wb‡R Ki|

#include<stdio.h> #include<conio.h> main(){ int num,i; printf("\nGive your number = "); scanf("%d",&num); while(num != 0){

Page 22: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

22

printf("%d",num%10); num = num/10; } getch();

}

63. What do you mean by array?

Ans: It is one kind of variable which can hold more than one same type of data and share a common name.

64. What is the meaning of the following declaration or statements?

(i) int dhaka[5];

Ans: The variable dhaka would hold number of five integer type data.

DËit GLv‡b dhaka variable 5 wU interger type of data store Ki‡Z cvi‡e| hvnv wP‡Îi mvnv‡h¨ †`Lv‡bv nj|

dhaka

0 1 2 3 4

dhaka[0] dhaka[1] dhaka[4]dhaka[3]dhaka[2] (ii) float kul[6];

Ans: The variable kul would hold number of six float type data.

DËit GLv‡b kul variable 6 wU float type of data store Ki‡Z cvi‡e|

65. What is the meaning of the statement dhaka[2] = 25; ?

DËit GLv‡b dhaka GKwU array variable. GB variable-Gi 2 bs index-G 25 store n‡e| hvnv wbb¥iy‡c †`Lv‡bv hvq|

dhaka

0 1 2 3 4

dhaka[0] dhaka[1] dhaka[4]dhaka[3]dhaka[2]

25

Page 23: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

23

66. for loop e¨envi K‡i Dc‡iv³ array variable G data store Ki Ges †`LvI| while loop e¨envi K‡i GB program wU wb‡R Ki|

#include<stdio.h> #include<conio.h> main(){ int k,n,a[100]; printf("\nHow many numbers you want to read = ?" ); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter a[%d] = ”,k); scanf("%d",&a[k]); } for(k=0; k<n; k++){ printf("%4d",a[k]); } getch(); }

67. for loop e¨envi K‡i Dc‡iv³ array variable G data store Ki Ges †m¸wj array ‡_‡K Dëv µ‡g gwbU‡i †`LvI| while loop e¨envi K‡i GB program wU wb‡R Ki|

#include<stdio.h> #include<conio.h> main(){ int k,n,a[100]; printf("\nHow many numbers Do you want to read = ?"); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter a[%d] = ",k+1); scanf("%d",&a[k]); } for(k=n-1; k>=0; k--){ printf("%4d",a[k]); } getch(); }

68.

Page 24: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

24

69. Write a program that can store some integer values in an array variable whose name is ‘moon’ and print only the odd and even numbers from it seperately. wb‡Pi program wU while loop Ges do - while loop w`‡q mgvavb Ki|

#include<stdio.h> #include<conio.h> main(){ int k,n,moon[100],hallow; printf("\nHow many numbers you want to read = ?" ); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter a[%d] = ",k+1); scanf("%d",&moon[k]); } for(k=0; k<n; k++){ hallow = moon[k] % 2; if(hallow != 0){ printf("%4d",moon[k]); } } getch(); }

70. Write a program that can store some integer values in an array variable whose name is ‘moon’ and print the maximum numbers or values from it. Here the program is solved by while loop but now you have to solve it by using for loop and do-while loop.

#include<stdio.h> #include<conio.h> main(){ int k,n,moon[200],max; printf("Give the value of n = "); scanf("%d",&n); k = 0; while(k<n){ printf("Enter a value = "); scanf("%d",&moon[k]);

Page 25: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

25

k = k+1; } max = moon[0]; k = 1; while( k < n){ if( max < moon[k]){ max = moon[k]; } k = k + 1; } printf("The maximum number is = %d",max); printf("\nGood by");

}

71. Write a program that can store some integer values in an array variable whose name is ‘moon’ and print the minimum numbers or values from it.

#include<stdio.h> #include<conio.h> main(){ int k,n,moon[200],min; printf("Give the value of n = "); scanf("%d",&n); k = 0; while(k<n){ printf("Enter a value = "); scanf("%d",&moon[k]); k = k+1; } min = moon[0]; k = 1; while( k < n){ if( min > moon[k]){ min = moon[k]; } k = k + 1; } printf("The minimum number is = %d",min); printf("\nGood by");

Page 26: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

26

}

72. Write a program which will take an integer value ‘n’ from key board and produce like following program.

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

.. .. .. .. .. .. ..

.. .. .. .. .. .. ... …

1 2 3 4 5 6 7 8 9 10

#include<stdio.h> #include<conio.h> #include<dos.h> main(){ int j,k,n; printf("\nHow many numbers Do you want to read = ?"); scanf("%d",&n); for(j = 1; j<n; j++){ for(k =1; k<=j; k++){ printf("%3d",k); } printf("\n"); delay(200); } getch(); }

73. Write a program which will take any integer number ‘n’ from key board and find out those numbers which will be dividable (fvM‡kl k~b¨ nB‡e) by both the 2 and 3 .

#include<stdio.h> #include<conio.h>

Page 27: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

27

main(){ int j,k,n; printf("\nHow many numbers Do you want to read = ?"); scanf("%d",&n); for(j = 1; j<n; j++){ if( j%2 == 0 && j%3 == 0){ printf("%3d",j); } } getch(); } 74. Write a program which will take any integer number ‘n’ from key board and find out

those numbers which will be dividable by 3 but not dividable by 5. (3 Øviv fvM Ki‡j fvMdj k~b¨ nB‡e wK›Zz 5 Øvi fvM Ki‡j fvMdj k~b¨ nB‡e bv)

#include<stdio.h> #include<conio.h> main(){ int j,k,n; printf("\nHow many numbers Do you want to read = ?"); scanf("%d",&n); for(j = 1; j<n; j++){ if(j%3 == 0){ if(j%5 != 0){ printf("%3d",j); } } } getch(); } 75. Write a program which will take any integer number ‘n’ from key board and test weather

it is a prime number or not. (‡gŠ wjK msL¨v wK bv Zv hvPvB Ki|)

#include<stdio.h> #include<conio.h> main(){ int j,flag,n;

Page 28: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

28

printf("\nWhat number do you want to test = "); scanf("%d",&n); flag = 0; j = 2; while(j<= n-1 && flag == 0){ if(n%j == 0){ flag = 1; } j = j+1; } if(flag == 1){ printf("\n%d is not prime number",n); } else { printf("\n %d is prime number",n); } getch(); }

Page 29: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

29

Second Part of C Programming

76. Write a program which will take two integers from key board and find out GCD of them.

#include<stdio.h> #include<conio.h> main(){ int gcd,num_one,num_two,tem; printf("\nGive the first number = "); scanf("%d",&num_one); printf("\nGive the second number = "); scanf("%d",&num_two); if(num_one < num_two){ tem = num_one; num_one = num_two; num_two = tem; } if( num_one % num_two == 0){ gcd = num_two; } while( num_one % num_two != 0){ tem = num_two; num_two = num_one % num_two; num_one = tem; if(num_one % num_two == 0){ gcd = num_two; } } printf("The GCD is = %d",gcd); getch(); }

Page 30: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

30

77. Write a program which will take two integer numbers from key board and find out LCD of them.

#include<stdio.h> #include<conio.h> main(){ int lcd,num_one,num_two,tem; int k; printf("\nGive the first number = "); scanf("%d",&num_one); printf("\nGive the second number = "); scanf("%d",&num_two); if(num_one < num_two){ tem = num_one; num_one = num_two; num_two = tem; } tem = num_one; if( num_one % num_two == 0){ lcd = num_one; } k = 2; while( num_one % num_two != 0){ num_one = tem * k; if(num_one % num_two == 0){ lcd = num_one; } k = k + 1; } printf("The LCD is = %d",lcd); getch(); }

78. Suppose you have an integer type of array which has some integer numbers. You have to print all the odd numbers from the array on the monitor.

#include<stdio.h> #include<conio.h>

Page 31: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

31

main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } printf("\nTotal array values are follows\n"); printf("\n-----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } k = 0; printf("\n\nThe odd number are as follows:\n"); printf("\n-------------------------------\n"); while(k<n){ if(a[k] % 2 == 1){ printf("%4d",a[k]); } k = k + 1; } getch(); }

79. Suppose you have an integer type of array which has some integer numbers. You have to

print all the even numbers from the array on the monitor.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){

Page 32: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

32

printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } printf("\nTotal array values are follows\n"); printf("\n-----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } k = 0; printf("\n\nThe even number are as follows:\n"); printf("\n-------------------------------\n"); while(k<n){ if(a[k] % 2 == 0){ printf("%4d",a[k]); } k = k + 1; } getch(); }

80. Suppose you have an integer type of array which has some integer numbers. You have to print all the numbers from the array on the monitor which are even and dividable by 5.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); }

Page 33: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

33

printf("\nTotal array values are follows\n"); printf("\n-----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } k = 0; printf("\n\nEven and dividable numbers as follow s:\n"); printf("\n-------------------------------\n"); while(k<n){ if(a[k] % 2 == 0 && a[k] % 5 == 0){ printf("%5d",a[k]); } k = k + 1; } getch(); }

81. Suppose you have an integer type of array which has some integer numbers. You have to print all the numbers from the array on the monitor which are odd and dividable by 3.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } printf("\nTotal array values are follows\n"); printf("\n-----------------------------\n"); k = 0; while(k<n){

Page 34: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

34

printf("\na[%d] = %d",k,a[k]); k = k + 1; } k = 0; printf("\n\nEven and dividable numbers as follows :\n"); printf("\n-------------------------------\n"); while(k<n){ if(a[k] % 2 == 1 && a[k] % 3 == 0){ printf("%5d",a[k]); } k = k + 1; } getch(); }

82. Suppose you have an integer type of array which has some integer numbers. You have to print all the numbers from the array on the monitor which are dividable by 5.

83. Suppose you have an integer type of array which has some integer numbers. You have to print all the prime numbers from the array on the monitor.

84. Suppose you have an integer type of array which has some integer numbers. You have to print all the prime numbers from the opposite direction of the array on the monitor.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } printf("\nTotal array values are follows\n"); printf("\n-----------------------------\n"); k = 0; while(k<n){

Page 35: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

35

printf("\na[%d] = %d",k,a[k]); k = k + 1; } k = n-1; printf("\n\nEven and dividable numbers as follow s:\n"); printf("\n-------------------------------\n"); while(k>=0){ printf("%5d",a[k]); k = k - 1; } getch(); }

85. Suppose you have an integer type of array which holds some integer numbers. You have to find out the position of a searching number which will be given through key board.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\nGive or write the searching value = ") ; scanf("%d",&svalue); i = 0; flag = 0; while(i<=n){

Page 36: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

36

if(a[i] == svalue){ pos = i; flag = 1; break; } i = i+1; } if(flag == 0) { printf("\nThe number %d is not in the array",sv alue); } else { printf("\nThe %d is present in the array",svalu e); printf("\nPosition of the searching value = %d" ,pos); } getch(); }

86. Suppose you have an integer type of array which has some integer numbers. You have to find out the number which will be given through key board and replace that number with a new one.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1;

Page 37: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

37

} printf("\nGive or write the searching value = ") ; scanf("%d",&svalue); i = 0; flag = 0; while(i<=n){ if(a[i] == svalue){ pos = i; flag = 1; break; } i = i+1; } if(flag == 0) { printf("\nNumber %d is not in the array",svalue ); } else { printf("\nNumber %d is present in the array",sv alue); printf("\nPosition of the searching value = %d" ,pos); printf("\n\nEnter the new value = "); scanf("%d",&newvalue); a[pos] = newvalue; printf("\nNumbers after replaced new numbers "); printf("\n----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } } getch(); }

Page 38: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

38

87. Suppose you have an integer type of array which has some integer numbers. You have to find out the number which will be given through key board and delete that number from the array.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\nGive or write the searching value = ") ; scanf("%d",&svalue); i = 0; flag = 0; while(i<=n){ if(a[i] == svalue){ pos = i; flag = 1; break; } i = i+1; } if(flag == 0) { printf("\nThe number %d is not in the array",sv alue); } else {

Page 39: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

39

printf("\nNumber %d is present in the array",sv alue); printf("\nPosition of the searching value = %d" ,pos); for(k=pos;k<n;k++){ a[k] = a[k+1]; } printf("\nNum after deleting searching value"); printf("\n----------------------------\n"); k = 0; while(k<n-1){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } } getch(); }

88. Suppose you have an integer type of array which has some integer numbers you have to insert a new value in the first position of that array.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter a[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\n-----------------------\n"); for(k = n; k>0; k--){ a[k] = a[k-1];

Page 40: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

40

} n = n+1; printf("\nInsert the new value = "); scanf("%d",&newvalue); a[0] = newvalue; printf("\nAfter inserting new value"); printf("\n-----------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } getch(); }

89. Suppose you have an integer type of array which has some integer numbers you have to insert a new value in the last position of that array.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter a[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\n-----------------------\n"); printf("\nInsert the new value = "); scanf("%d",&newvalue); a[n] = newvalue;

Page 41: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

41

n = n+1; printf("\nAfter inserting new value"); printf("\n-----------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } getch(); }

90. Suppose you have an integer type of array which has some integer numbers you have to insert a new value after a specific number in the array.

#include<stdio.h> #include<conio.h> main(){ int a[50]; int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\nGive or write the searching value = ") ; scanf("%d",&svalue); i = 0; flag = 0; while(i<=n){ if(a[i] == svalue){ pos = i;

Page 42: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

42

flag = 1; break; } i = i+1; } if(flag == 0) { printf("\nNumber %d is not in the array",sval ue); } else { printf("\nNumber %d is present in array",sva lue); printf("\nPosition the searching value = %d" ,pos); for(k=n; k>pos+1; k--){ a[k] = a[k-1]; } n = n+1; printf("\nInsert the new value = "); scanf("%d",&newvalue); a[pos+1] = newvalue; printf("\nAfter inserting new value"); printf("\n----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } } getch();

}

91. Suppose you have an integer type of array which has some integer numbers you have to insert a new value before a specific number in the array.

#include<stdio.h> #include<conio.h> main(){ int a[50];

Page 43: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

43

int n,i,k,svalue,pos,flag,newvalue; printf("\nGive the total number n = "); scanf("%d",&n); for(k = 0; k<n; k++){ printf("\nEnter akmol[%d] = ",k+1); scanf("%d",&a[k]); } k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } printf("\nGive or write the searching value = ") ; scanf("%d",&svalue); i = 0; flag = 0; while(i<=n){ if(a[i] == svalue){ pos = i; flag = 1; break; } i = i+1; } if(flag == 0) { printf("\nNumber %d is not in the array",sval ue); } else { printf("\nNumber %d is present in array",sva lue); printf("\nPosition the searching value = %d" ,pos); for(k=n; k>pos; k--){ a[k] = a[k-1]; } n = n+1; printf("\nInsert the new value = ");

Page 44: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

44

scanf("%d",&newvalue); a[pos] = newvalue; printf("\nAfter inserting new value"); printf("\n----------------------------\n"); k = 0; while(k<n){ printf("\na[%d] = %d",k,a[k]); k = k + 1; } } getch(); }

92. Write a program which will take any integer number ‘n’ from key board and test weather it is a prime number or not. (‡gŠ wjK msL¨v wK bv Zv hvPvB Ki|)

#include<stdio.h> #include<conio.h> main(){ int i,k,number,flag; printf("\nGive a positive number to test = "); scanf("%d",&number); if(number == 1 || number == 2 || number == 3) { printf("%d is prime",number); } else { flag = 0; i = 2; while(i<number){ if(number % i == 0){ flag = 1; } i = i+1; } if(flag == 0) {

Page 45: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

45

printf("%d is prime",number); } if(flag == 1){ printf("%d is not prime",number); } } getch(); }

93. What do you mean by user define function? Explain with example.

Ans: wKQz code Avgiv GKwU bv‡gi Awa‡b wjL‡Z cvwi| bvg mn H code ¸wj‡K GK‡Î Avgiv function ej‡Z cvwi| wb‡Pi D`vni‡Y add bv‡gi GKwU function ‰Zwi Kiv n‡q‡Q hvnv main function – Gi Dc‡i Av‡Q| Zvici main function – Gi wfZ‡i †_‡K add bv‡gi function - †K call Kiv n‡q‡Q|

Formal Parameter: main function – Gi Dc‡i †hLv‡b add declare Kiv n‡q‡Q †mLv‡b x Ges y ‡K formal parameter e‡j|

Actual Parameter: main function – Gi wfZ‡‡i †hLv‡b add function - †K call Kiv n‡q‡Q †mLv‡b a Ges b ‡K actual parameter e‡j|

Parameter passing: program - †K call Kivi mgq actual parameter ‡_‡K value wj formal parameter - transfer nq| GB NUbv †K Parameter passing e‡j|

#include<stdio.h>

#include<conio.h>

add(int x, int y){ Int z;

z = x +y;

printf( “\n %d + %d = %d”,x,y,z);

}

main(){

int a,b;

printf(“\nEnter the value of a = “);

scanf(“%d”,&a);

printf(“\nEnter the value of b = “);

scanf(“%d”,&b);

add(a,b); getch();

}

x and y is Formal parameter

a and b is actual parameter

94. What do you mean by user define function?

Page 46: SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY … · SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY 19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website:

SHEIKH SHIBLY NOMANY SPORSO PUBLISHER POWERED BY SPORSO GROUP OF COMPANY

19, BUGHMARA EIDGHA LANE, KHULNA-9100,BD MOB: +8801756448419, Website: sporsogroup.wordpress.com E-Mail: [email protected]

46

Ans: The functions which are designed by user or programmer is called user define function?

95. What is the difference between main function and other function?

SL. main function Other user define function

1 Every program must contain only one main() program

It may not contain in a program

2 Compilation must start from main() function

Compilation must not start from other any function.

3 It’s a tradition calling the other function staying in the main function.

Normally it is call by main function

96. Prepare a function whose name is hallow. Passing a parameter to that function write the following series (1 3 5 7 ……..n)

#include<stdio.h> #include<conio.h> hallow(int x){ int i; printf("\nThe series is as follows\n"); printf("\n---------------------------\n\n"); for(i = 1; i<= x; i++){ if(i % 2 == 1){ printf("%3d",i); } } printf("\n\n---------------------------\n"); } main(){ int a; printf("\nGive the value of a = "); scanf("%d",&a); hallow(a); printf("Good by"); getch(); }