lecture notes on programming fundamental using … · 2013. 1. 21. · collage of information...

17
Collage of Information Technology, University of Babylon, Iraq [email protected] By Dr. Samaher Hussein Ali LECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE Department of Software The University of Babylon 21 January 2013 1

Upload: others

Post on 01-Feb-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

  • Collage of Information Technology, University of Babylon, Iraq

    [email protected]

    By Dr. Samaher Hussein Ali

    LECTURE NOTES ON PROGRAMMING

    FUNDAMENTAL USING C++ LANGUAGE

    Department of Software The University of Babylon

    21 January 2013 1

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    2 Notes of Lecture 6

    Q1//write a program to find febonatshy serial 1 1 2 3 5 8 13 21 34 ….. #include #include void main() { clrscr(); int i,n,a=0,b=1,c; coutn; cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    3 Notes of Lecture 6

    Q2//Calculator program #include #include void main() { Clrscr(); float a,b,c; char sign; cin>>a; cin>> sign; cin>>b; switch (sign) { case '+': cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    4 Notes of Lecture 6

    Q3//Write a program to find N! . #include #include void main() { clrscr(); int a,b,c=1; cin>>b; for(a=1;a

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    5 Notes of Lecture 6

    Q4//write a program to find power of number #include #include void main() { clrscr(); int x,y; float w=1; coutx; couty; for(int i=1;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    6 Notes of Lecture 6

    Q5//what the output of this code #include #include void main() { Clrscr(); int a=3,b=2,c=a*b; b++; a=b++; b++; cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    7 Notes of Lecture 6

    Q6// find the output that generation the following shape #include * * #include * * void main() * { * * clrscr(); * * int x; int k=0; for(int i =1;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    8 Notes of Lecture 6

    Q7// Write Program to Print the Following Shape 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 #include #include void main() { clrscr(); for(int i=1;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    9 Notes of Lecture 6

    Q8 //Test Character Small or Capital #include #include void main() { clrscr(); char a,b; couta; if(a>=65 && a

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    10 Notes of Lecture 6

    Q9// Test Number if Prime or Not #include #include void main() { clrscr(); int x,result=0; cin>>x; for(int i=2;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    11 Notes of Lecture 6

    Q10 //Write Program to print the Following Form 1 2 3 4 5 6 7 8 9 10 #include void main() { int k=1; for(int i=0;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    12 Notes of Lecture 6

    Q11//Write Program Find Cube and Square to Five Digit #include #include void main() { int a,b; for(int i=0;i>x; cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    13 Notes of Lecture 6

    Q13// Write a program to find the greatest common divisor (GCD) between two numbers #include #include void main() { clrscr(); int x,y; coutx>>y; while(xx) y=y-x; } cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    14 Notes of Lecture 6

    Q14// Write program to reverse any number; such as 1234-4321 #include void main() { int x,y; coutx; while(x!=0) { y=x%10; x=x/10; cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    15 Notes of Lecture 6

    Q16//Find dividing two numbers without using the process of division #include #include void main() { clrscr(); int x,y,m=0; coutx>>y; if((x>y)&&(y!=0)) { while(x!=0) { x=x-y; m=m+1; } } cout

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    16 Notes of Lecture 6

    Q17// Write a program to print and find a solution following sequence of numbers 1/1 + 4/2 + 3/3 + 6/4 + 5/5 + 8/6 + 7/7+…………n #include #include void main() { clrscr(); int n,a,b,sum=0; coutn; for(int i=1;i

  • Dr. Samaher Hussein Ali

    Examples:

    21 January 2013

    17 Notes of Lecture 6

    Q18 // Write Program to print the following form. * * * * * * * * * * * * * #include #include void main() { clrscr(); for(int i = 1;i