0% found this document useful (0 votes)
4 views8 pages

C Programming Exercises for Engineering Students

This document presents 5 solved programming exercises in C. The exercises cover: 1) Variable declaration and use of pointers; 2) Data input, use of pointers, and comparison; 3) Record structure; 4) Use of pointer for structure; 5) Iterative and recursive counting. For each exercise, the statement, code, and image of the compiled program are presented.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

C Programming Exercises for Engineering Students

This document presents 5 solved programming exercises in C. The exercises cover: 1) Variable declaration and use of pointers; 2) Data input, use of pointers, and comparison; 3) Record structure; 4) Use of pointer for structure; 5) Iterative and recursive counting. For each exercise, the statement, code, and image of the compiled program are presented.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTERNATIONAL UNIVERSITY CENTER UNINTER

POLYTECHNIC HIGH SCHOOL


BACHELOR'S DEGREE IN ELECTRICAL ENGINEERING: ELECTRONICS SPECIALIZATION

PROGRAMMING LANGUAGE DISCIPLINE

PRACTICAL ACTIVITY

FABIELE ZANQUETTA MENEGUZZI – RU: 1383939


PROFESSOR WINSTON SEN LUN FUNG

NEW HAMBURG - RS
2019
1 EXERCISE

STATEMENT:

Write an algorithm in C language with the following instructions: 1. Declare three


variables (integer, real, and char); 2. Declare three pointers; 3. Associate the variables with
pointers; 4. Modify the values of each variable indirectly using the
associated pointers. To store the values in the variables, store in the
variablechar the first letter of your name, in the variableint the last two digits
from your RU and in the variable the last 4 digits of your RU, with the last 2 being the
values with comma; 5. Print on the screen the values of the variables before and after the

modification

WRITTEN CODE (PART 1):

#include<stdio.h>
#include <stdlib.h>

int main(void) {

int *integer; // INPUT VARIABLES


float *real; // I USED THE FLOAT FUNCTION BECAUSE OF THE COMMA
char *_char;

printf("integer %d\n", &integer);//HERE I ASSOCIATED THE VARIABLES WITH THE POINTERS


printf("real %d\n", &real);
printf("_char %d\n", &_char);// FROM 11 TO 13 I DID TO PRINT ON THE SCREEN

system("pause");
return 0;
}

IMAGE OF THE COMPILED CODE WORKING (1st PART):

1
WRITTEN CODE (PART 2):

#include<stdio.h>
#include <stdlib.h>

int main(void) {

int *integer; //INPUT VARIABLES AND POINTERS


float *real; // I USED THE FLOAT FUNCTION BECAUSE OF THE COMMA
char *_char;

printf("integer %d\n", &integer = 39);//HERE I STARTED THE MODIFICATIONS WITH MY


RU
printf("real %d\n", &real = 39.39);
printf("_char %d\n", &_char ='F');// MADE FROM 11 TO 13 TO PRINT ON SCREEN

system("pause");
return 0;

IMAGE OF THE COMPILED CODE WORKING (PART 2):

2EXERCISE

STATEMENT:

Write an algorithm in C LANGUAGE that stores your RU in memory and the


value 1234567, both entered by the user on the screen. Then, print on the screen
both RU using pointers. The algorithm will also have to compare the two RUs
using pointers and print on the screen which is the largest
WRITTEN CODE:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv // INTRODUCTION OF VARIABLES
{
int ru; THE WAY I FOUND TO OPT FOR THE GREATER FUNCTION
int x;
int *pointerRu = &ru; // I ASSOCIATED POINTER WITH OPERATORS
int *pointerX = &x;

printf(" Enter your Ru: \n"); // PRINTING ON THE INITIAL SCREEN


scanf_s("%d\n", &ru);
Enter a value:
scanf_s("%d\n", &x);

printf(" Student's ID: %d \n", *pointerID);


Value of the entered: %d

if (*pointerRu > *pointerX)// IF IT IS GREATER IT WILL BE DIFFERENT


printf(" The value of Ru is greater than the value X entered "); // PRINTING ON SCREEN
IT IS BIGGER
else if (*ponteiroRu < *ponteiroX) printf(" The value of Ru is less than the Value X");
typed";}
else printf(" The values are equal. ");

system("pause");
return 0;
}

IMAGE OF THE FUNCTIONING COMPILED CODE:

3EXERCISE

STATEMENT:
Create an algorithm in C language with the following functionalities: Receive a
record, with two fields, as input data; The first field is a vector
that will store the name of the student; The second field is a variable of type
integer that will store the student's RU; Prints the stored data on the screen
structure

WRITTEN CODE:

#include <stdio.h>
#include <stdlib.h>

main() {

int num; //INPUT VARIABLES

char name[20];

printf("Enter the Student's name: \n"); //PRINTING THE INSTRUCTION

scanf_s("%d", name);// WRITES WHAT THE USER TYPES

printf("Enter the student code: \n");//PRINTING THE INSTRUCTION

scanf_s("%d", &num);// WRITES WHAT THE USER TYPES

printf("The name of the student is: %s.\n", name);// HERE FROM 18 TO 20 IT PRINTS THE
RESULTS

Student code: %d

system("pause");
return 0;

IMAGE OF THE COMPILED CODE WORKING:


4EXERCISE

STATEMENT:

Replicate exercise 3. However, now, declare a pointer to the structure of


heterogeneous data. At the time of reading the data and printing it on the screen, use the
pointer to fetch the contents of the fields. Print your RU on the screen as well
fabric.

WRITTEN CODE:

#include <stdio.h>
#include <stdlib.h>

main() {

int numRU;//INPUT VARIABLES

int num;

printf("Enter a number: \n");//PRINTING THE INSTRUCTION

scanf_s("%d", &num); // WRITES WHAT THE USER TYPES

printf("Enter the student code: \n"); //PRINTING THE INSTRUCTION

scanf_s("%d", &numRU);// WRITES WHAT THE USER TYPES

printf("The number is: %d\n", num);// HERE FROM 18 TO 20 PRINTS THE RESULTS

Student code: %d

system("pause");
return 0;

IMAGE OF THE COMPILED CODE RUNNING:


5EXERCISE

STATEMENT:

Write an algorithm in C language that contains two entered integer numbers.


on the screen by the user: a. The first number marks a start; b. The second number
marks an end; The algorithm will count how many numbers exist between the start
(first input) and the end (second input). The display on the user's screen must
to be done in two ways: a. Iterative; b. Recursive; When included in your report
an image of your code working, run it using as value
at first the last 2 values of your RU and the final value the number 99.

WRITTEN CODE:

Include <stdio.h>
#include <stdlib.h>

int count_iterative(int start,int final) {//DECLARE THE INTERACTIVE VARIABLES

int i = 0, counter = 0;

for (i = start; i <= end; i++) {


counter++;
}

return counter;
}

int recursive_count(int inicio,int final) {//DECLARE THE VARIABLES OF THE RECURSIVE

int counter;

if (start == end) {
return 1;
}
else {

counter = 1 + recursive_count(start + 1, end);

return count;

}
int main(void) {

int b = count_iterative(15, 99);

int a = recursive_count(15, 99);

printf("The result was: %d", a);// PRINTS THE RESULTS ON THE SCREEN

The result was: %d

system("pause");
return 0;

IMAGE OF THE COMPILED CODE WORKING:

You might also like