# ITEC213 Structured Programming Eastern Mediterranean University ...

Λογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 4 χρόνια και 7 μήνες)

384 εμφανίσεις

ITEC
213

Structured Programming

Eastern Mediterranean University

School of Computing and Technology

Information Technology / Compute
r

Programming

Lab

#1

2010
-

2011 Fall Semester

Instructors: Cantas Ozerek

Nazife Dimililer

Akile Yuvka

Research
Assistant: Laika Karsili

Task 1: Complete the following program.

(a)

Write the definition of incrementby2 so that the following output is produced.

#include <stdio.h>

void incrementby2(int *);

int main()

{

int num1=10,num2=20,num3;

printf("Before
incerement %d ", num1);

incrementby2(&num1);

printf("After increment %d
\
n", num1) ;

}

/*Write the function definition of incrementby2 below*/

void incrementby2(int *p)

{

*p=*p+2;

}

(b)

Modify the function incrementby2 according to the following main

#include <stdio.h>

/*write the function prototype here*/

int

incrementby2(int *);

int main()

{

int num1=10,num2=20,num3;

printf("Before incerement %d, ", num1);

printf("After increment %d
\
n",incrementby2(&num1)) ;

}

/*write the function defin
ition here */

int incrementby2(int *p)

{

*p=*p+2;

return *p;

}

Task 2 : Complete the following program according to the following specification

Encrypt function increases each character of the argument by 3.

Decrypt function decreases each character o
f the argument by 3.

Hint: You can use strlen to find the length of a string or you can check for end of string character ‘
\
0’.

#include <stdio.h>

#include <string.h>

/*Declare function prototypes here*/

void encrypt(char *);

void decrypt (char *);

void

main()

{

char passwd[6];

scanf("%s",passwd);

printf("You have entered %s
\
n",passwd);

encrypt(passwd);

\
n",passwd);

decrypt(passwd);

\
n",passw
d);

}

/*Write the code for encrypt function here*/

void encrypt(char *p)

{

int len=strlen(p);

for(int i=0;i<len;i++)

{

*p=(*p+3);

p++;

}

}

/*Write the code for decrypt function here*/

void decrypt(char *p)

{

int len=strlen(p);

for(int i=0;i<len;i++)

{

*p=(*p
-
3);

p++;

}

}

Task 3 : Use dynamic memory allocation to declare an array of real numbers to enter salaries
of N employees. The value of N will be entered by the user.

Enter the data from keyboard.

List all s
alaries on screen in reverse of data entry

#include <stdio.h>

#include <alloc.h>

int main()

{

int N;

float *salaries;

printf("Pls enter the number of employees in your company :");

scanf("%d",&N);

salaries=(float *)malloc(sizeof(float)*N);

printf("Enter the salaries
\
n");

for(int i=0;i<N;i++)

{

printf("Enter salary for employee %d : ",i+1);

scanf("%f",salaries+i);

}

for(int i=N
-
1;i>=0;i
--
)

{

printf("Employee %d : %.1f
\
n",i+1,*(salaries+i));

}

}