CSE102 – Computer Programming Solved

$ 29.99
Category:

Description

Homework #3
Hand in: A student with number 20180000001 should hand in a zip file named 20180000001.zip which includes 20180000001_part1.c, 20180000001_part2.c and 20180000001_part3.c for this homework.

Part 1. [15pts] Write a complete program describing all the tasks below.
In the main function, the program respectively request an Integer (N), an operation flag, and finally a flag to decide if it is going to work on odd / even numbers. The program will support only 2 operations, addition or multiplication. According to the selection of the flags, the program will calculate the sum/multiplication of the odd/even numbers between the range of [1,N]. The addition and the multiplication operations should be done by using two different functions. The operation selection should be determined by using operation flag with switch-case, after that, the integer and the other flag should be used to call the related function. If user enters invalid value for the flags, the program should print an error message.
Function prototypes are :
int sum (int n, int flag) int mult (int n, int flag)
Examples:

Part 2. [35pts] Write a complete program which takes an integer N from the user and checks the every integer from 2 to that number if they are prime or not. The primality testing is made by a function with the following information:
A is prime if A is not dividible by any integer X where X is;

1<𝑋≤√𝐴
This operation should be done in a function, the function should return a flag if the integer is prime, or should return the least divisor of that integer if it is not a prime. In the main function, you should use a loop to check every A between 1<𝐴<N, obtain a result by using the function and finally print it.
Only ‘for’ loops should be used. You are allowed to use sqrt() function from math library to calculate the square root.
Function prototype is : int isprime (int a)
Example:

Part 3. [50pts] Write a complete program describing all the tasks below.
In the main function, 2 integers are requested from the user. These integers will work as decimal numbers but you are expected to work on them as binary numbers and implement AND logical operator without using “&”. To do this,
1. The program should check if the integers are binary or not (their digits must be 0, 1). If the integers are not binary, the program should ask for new integers again and again until it obtains a proper pair. 2. The program should check if the integers’ lengths (number of digits) are the same or not. If the lengths are not the same, the program should ask for new integers again and again until it obtains a proper pair.
3. After obtaining a decent integer pair (2 binary numbers with the same length), the program should implement logical AND operation on these integers, without using ‘&’ operator. Here, there should be a function which calculates the result of the AND operation and returns it to the main(). And the result should be printed in the main() function.

Function prototype is : int andop (int a, int b)

Note that you can’t use arrays & you are allowed to use ‘do-while’ or ‘while’ loops only.
Example:

General Rules:

1. Obey and do not break the function prototypes that are shown on each part, otherwise, you will get zero from the related part.
3. Note that if any part of your program is not working as expected, then you can get zero from the related part, even it’s working in some way.
4. Upload your .zip file on to Moodle to deliver your homework. The zip file must consist of three .c file that contains your solutions. Name format can be found on the top of this homework sheet.
5. You can ask any question about the homework by sending an email to sgulmez2018@gtu.edu.tr or by using the forum in the Moodle page of the course.

Reviews

There are no reviews yet.

Be the first to review “CSE102 – Computer Programming Solved”

Your email address will not be published. Required fields are marked *