Programming Fundamentals - Lecture 04
Programming Fundamentals - Lecture 04
Lecture No. 4
Key Words of C
main
if
else
while
do
for
Memory
x=2+4;
=6;
Memory
a
x=a+b;
x
#include <iostream.h>
main ( )
{
int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10 ;
int TotalAge ;
int AverageAge ;
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 ;
}
Quadratic Equation
In algebra
y = ax2 + bx + c
In C
y = a*x*x + b*x + c
a*b%c +d
a*(b%c) = a*b%c
Discriminant
b2 - 2a
4c
= b*b - 4*a*c /2 *a
answer
Incorrect
Solution
= (b*b - 4*a*c) /(2 *a)
Correct answer
Interesting Problem
Given a four-digit integer,
separate and print the
digits on the screen
Analysis
Number = 1234
Code
#include <iostream.h>
main ( )
{
int number;
int digit;
cout << Please enter a 4 digit integer : ;
cin >> number;
digit = number %10;
cout <<The digit is: << digit << \n;
number = number / 10;
digit = number % 10;
cout <<The digit is: << digit << \n;
number = number / 10;
digit = number % 10;
cout <<The digit is: << digit << \n;
number = number / 10;
digit = number % 10;
cout <<The digit is: << digit;
}
\n