Sunteți pe pagina 1din 2

BEC/ BEE/BEP/1314I

Faculty of Electrical & Electronics Engineering


BEE1222 Computer Programming

Name: ______________________________ ID: __________________________


Section: ____________________________ Date: _______________________
Lab
Mapping CO,PO,Domain,KI : CO1,PO1,C3
CO1: Demonstrate the basic principle and concept of computer programming to solve the basic problem with
utilization the knowledge of mathematics and sciences.
PO1: Acquire and apply knowledge of sciences and electrical and electronics engineering fundamentals.
C3: Use concept in a new situation or unprompted use of an abstraction. Applies what was learned in the
classroom in the work place.

Write a program using array for the following problem:


 Let user decide the number of array elements.
 Ask the user to enter integer values into array number using a while loop.
 Using a for loop, retrieve the values from array number, calculate the square of the
values using the pow() function and store the result in array square.

 Using a do-while loop, display all the values from array square on the screen.

SAMPLE OUTPUT
Please enter the number of array: 5

Enter an integer number : 3


Enter an integer number : 6
Enter an integer number : 2
Enter an integer number : 9
Enter an integer number : 7

= RESULT =
3 to the power of 2 is 9
6 to the power of 2 is 36
2 to the power of 2 is 4
9 to the power of 2 is 81
7 to the power of 2 is 49
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{

MSJ @ FKEE UMP


BEC/ BEE/BEP/1314I

int size,x,y;

printf("Please enter the number of array: ");


scanf("%d",&size);
int array[size];

for (x =0;x<size;x++)
{
printf("Enter an integer number: ");
scanf("%d",&array[x]);

printf("= RESULT = \n\n");

for (y = 0;y<size;y++)
{
printf("%d to the power of 2 is %2.2f \n ",array[y],pow(array[y],2));

return 0;
}

MSJ @ FKEE UMP

S-ar putea să vă placă și