Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please explain the coding using Cprogramming Language Problem 4. Series of integ

ID: 3754555 • Letter: P

Question

Please explain the coding using Cprogramming Language

Problem 4. Series of integers (25 points) Write a program that calculates the sum and product of series of integers. You will take 3 integers as input- starting number, step(increment) size and last number. For this problem, you might want to use for loop. Do not give large step size or last number, as the result of product might overflow Sample Input and Output: (Your code should print the red texts on the screen. Black texts are sample user inputs) Enter starting number: 1 Enter step size: 2 Enter last number: 10 Sample Output Sum of the series is 25 Product of the series is 945 Problem 5. Prime Number or Not! (15 points) Prime numbers are numbers that are bigger than one and cannot be divided evenly by any other number except 1 and itself. Write a program that takes an integer as input and determine whether it is a prime number or not For this code, you need to use both loop and if-else blocks Sample Input and Output: (Your code should print the red texts on the screen. Black texts are sample user inputs) Sample Input Sample Output Enter Number: 264 Enter Number: 37 Enter Number: 63 264 is not a prime number 37 is a prime number 63 is not a prime number

Explanation / Answer

Problem 4: Series of integers;

#include <stdio.h>
#include<graphics.h> //include graphics file to get color for text

int main(void)
{
textcolor(4); //set text color as RED
int last,step,i, start, sum = 0, pdt=1; //variable declaration
//read integer values for starting,step increament and end of loop
cprintf("Enter a starting integer: ");
scanf("%d",&start);

cprintf("Enter a step size: ");
scanf("%d",&step);
  
cprintf("Enter a last integer: ");
scanf("%d",&last);
  
for(i=start; i <= last; i+=2)
{
sum += i; // sum = sum+i;

   pdt *= i; // find product
}

//output sum

cprintf("Sum = %d",sum);

cprintf("Product = %d",pdt);


getch();
return 0;
}

problem 5: Prime number or not;

#include <stdio.h>
#include<graphics.h>
int main()
{
int n, i, flag = 0;
textcolor(RED);

cprintf("Enter a number: ");
scanf("%d", &n);

for(i = 2; i <= n/2; ++i)
{
// condition for nonprime number
if(n%i == 0)
{
flag = 1;
break;
}
}

if (n == 1)
{
cprintf("1 is a prime number.");
}
else
{
if (flag == 0)
cprintf("%d is a prime number.", n);
else
cprintf("%d is not a prime number.", n);
}
getch();
return 0;
}

In both case, use cprintf() function to get colored output.