C language program that needs to be finished. Please go here to locate the given code with 5 steps: bit (dot) ly (slash) 2kckkCm
Will give a thumb up!
CODE
#include <stdio.h>
void swapWithRef ( unsigned char *x, unsigned char *y )
{
unsigned char temp = *x;
*x = *y;
*y = temp;
}
unsigned int ComputeSum ( unsigned int data[ ] , unsigned int len )
{
unsigned int sum = 0 ;
for(int i=0; i<len; i++) {
sum += data[i];
}
return sum;
}
void ComputeSumOfOddNumbers ( unsigned int *ptr, unsigned int len, unsigned int *sum )
{
for (int i=0; i<len; i ++) {
if (ptr[i] % 2 == 0)
*sum += ptr[i];
}
}
void Increment(unsigned int *ptr , unsigned int len )
{
for (int i=0; i<len; i++) {
ptr[i] += 1;
}
}
int main ( )
{
unsigned char x = 'B', y = 'a' ;
printf ( " x = %c y = %c \n", x, y ) ;
swapWithRef(&x,&y) ;
printf ( " x = %c y = %c \n", x, y );
unsigned int data [ ] = { 11, 18, 7, 6 , 9};
// Ideally you should compute len. but it's okay for now.
unsigned int len = 5 ;
printf ( "Sum of all elements %d \n", ComputeSum ( data, len ) ) ;
unsigned int oddSum = 0 ;
ComputeSumOfOddNumbers ( data, len , &oddSum );
printf ( "Sum of all odd numbers %d \n", oddSum ) ;
oddSum = 0 ;
unsigned int *ptr = data ;
Increment ( ptr, len );
int i;
for ( i = 0 ; i < len; i++ )
printf ( "i= %d value = %d \n", i, data[i] );
}
Get Answers For Free
Most questions answered within 1 hours.