Department of Electrical Engineering EE:101 Computing Fundamentals and Programming
Department of Electrical Engineering EE:101 Computing Fundamentals and Programming
Course Instructor: Mr. Syed Basit Ali Dated: 10th Nov, 2019
a. Objective
The goal of this handout is to observe how a program works, how an output is displayed of
your work and also to get a know-how of how programming needs to be done step by step.
b. Equipment and Component
Component Description Value Quantity
Computer Available in lab 1
c. Conduct of Lab
1. Students are required to perform this experiment individually.
2. In case the lab experiment is not understood, the students are advised to seek help from
the course instructor, lab engineers, assigned teaching assistants (TA) and lab
attendants.
Statement 1 is executed (one time) before the execution of the code block.
Statement 3 is executed (every time) after the code block has been executed.
Example:
int main()
for(int num=1;num<=10;num++)
int square=num*num;
" = "<<square<<endl;
return 0;
}
Q.2 Output 1 to n Natural Numbers and also output their sum using for loop. (n will define
by user).
[2 Marks]
#include <iostream>
int main()
int n;
int sum = 0;
cin >> n;
sum = sum+i;
}
cout << "Sum = " << sum;
return 0;
Q.3: Write a program to add all number entered by user until user enters 0 using for loop
[2 Mark]
#include <iostream>
int main()
int n;
int sum = 0;
cin >> n;
sum = sum+i;
}
while(n!=0);
return 0;
Q.4: Write a program to calculate Factorial of any number given by user. [2 Marks]
#include <iostream>
int main() {
int number;
int factorial=1;
cin>>number;
factorial=factorial*a;
return 0;
}
Q.5: Write a program to find prime number within range of numbers defined by user. [2 Marks]
#include <iostream>
using namespace std;
int main()
{
int a, b, i, j;
if (a <= 2) {
a = 2;
if (b >= 2) {
cout << a << " ";
a++;
}
}
if (a % 2 == 0)
a++;
for (i = a; i <= b; i = i + 2) {
bool flag = 1;
if (flag == 1)
cout << i << " ";
}
return 0;
}
Conclusion:
I have learnt for loop in this lab.