1 / 17

Introduction to Programming

Introduction to Programming. Lecture 4. Key Words of C. main if else while do for. Memory. Memory. x = 2 + 4 ; = 6 ;. Memory. x = 2 + 4 ; = 6 ;. Memory. a. b. x = a + b ;. x. #include< iostream.h > void main() { int x=10; cout <<"the value of x is=";

oliana
Download Presentation

Introduction to Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Programming Lecture 4

  2. Key Words of C • main • if • else • while • do • for

  3. Memory

  4. Memory x = 2 + 4 ; = 6 ;

  5. Memory x = 2 + 4 ; = 6 ;

  6. Memory a b x = a + b ; x

  7. #include<iostream.h> void main() { int x=10; cout<<"the value of x is="; cout<<x<<endl; }

  8. #include<iostream.h> void main() { int x; cout<<"enter the value of x"; cin>>x; }

  9. #include<iostream.h> void main() { intx; inty; intz; cout<<"enter the value of x"; cin>>x; cout<<endl; cout<<"enter the value of y"; cin>>y; cout<<endl; z=x+y; cout<<"the answer is"; cout<<z; }

  10. Quadratic Equation • In algebra y = ax2 + bx + c • In C y = a*x*x + b*x + c

  11. a*b%c +d

  12. a*(b%c) = a*b%c • ?

  13. b2 - 2a 4c = b*b - 4*a*c /2 *a Incorrect answer Solution = (b*b - 4*a*c) /(2 *a) Correct answer

  14. No expression on the left hand side of the assignment • Integer division truncates fractional part • Liberal use of brackets/parenthesis

  15. TASK • Calculate average of the ages of three persons by using cin>>

  16. #include <iostream.h> main ( ) { int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10 ; intTotalAge ; intAverageAge ; cout << “ Please enter the age of student 1: “ ; cin >> age1 ; cout << “ Please enter the age of student 2: “ ; cin >> age2 ; : : TotalAge = age1+ age2 + age3+ age4+ age5+age6+ age7+ age8+age9 +age10 ; AverageAge = TotalAge / 10 ; cout<< “The average age of the class is :” << AverageAge ; }

More Related