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

Write a program to print the prime numbers from 1 to 100. (A prime integer is an

ID: 3795635 • Letter: W

Question

Write a program to print the prime numbers from 1 to 100. (A prime integer is any integer that can be divided evenly only by itself and 1) Requirement: use an array to take the number from 1 to 100 and another array to take the prime number. Write a C code to perform the following tasks: In main: Define an array of SIZE = 7 and initialize them with 3, 5, 7, 9, 11, 13, 15 Call function sum with the array and size as parameters Print each element of the array Print the sum In function sum: Use for-loop to calculate sum Write a C code to perform the following tasks: In main: Define an array of SIZE = 7 and initialize them with 3, 5, 7, 9, 11, 13, 15 Call function sum with the array and size, both passed in pointer representations Print each element of the array Print the sum In function sum: Take the parameters in pointer representations,

Explanation / Answer

#include <stdio.h>
int sum(int *array, int *size){
int i = 0;
int result = 0;
printf("Elements: ");
for(i=0;i<*size;i++){
printf("%d ",*(array+i));
result = result+*(array+i);
}
printf(" Sum of the number: %d ",result);
}

int main()
{
int array[7] = {2,3,4,5,6,7,8};
int size = sizeof(array)/sizeof(int);
printf(" size of the array :%d ",size);
sum(array, &size);

return 0;
}

Ouput:

sh-4.2$ main                                                                                                                                                    

size:7Elements: 2 3 4 5 6 7 8                                                                                                                                   

                                                                                                                                                                

Sum of the number: 35                                                                                                                                           

sh-4.2$ gcc -o main *.c                                                                                                                                         

sh-4.2$ main

size of the array :7   

Elements: 2 3 4 5 6 7 8   

Sum of the number: 35   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote