0% found this document useful (0 votes)
40 views4 pages

Exam

The function response takes an integer N as input and returns a string. It returns "FizzBuzz" if N is divisible by 15, "Fizz" if N is divisible by 3, "Buzz" if N is divisible by 5, or the string representation of N otherwise. The function accumulate_chars takes a string as input, converts each character to uppercase and lowercase, separates them with dashes, and returns the new concatenated string. The function calculateRunningTotal takes an array of numbers and its length as input. It calculates the product and sum of the numbers. It then returns different values based on whether the product is even/odd and whether certain numbers are present in the array.

Uploaded by

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

Exam

The function response takes an integer N as input and returns a string. It returns "FizzBuzz" if N is divisible by 15, "Fizz" if N is divisible by 3, "Buzz" if N is divisible by 5, or the string representation of N otherwise. The function accumulate_chars takes a string as input, converts each character to uppercase and lowercase, separates them with dashes, and returns the new concatenated string. The function calculateRunningTotal takes an array of numbers and its length as input. It calculates the product and sum of the numbers. It then returns different values based on whether the product is even/odd and whether certain numbers are present in the array.

Uploaded by

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

char * response( int, N) {

char *response = nalloc(0 * slieof(char));


if (N % 15 == 0) {
response = "FizzBuzz";

} else if (N % 3 == 0) {
response = "Fizz"

} else if (N % 5 ==0) {
response = "Buzz";

} else {
sprintf(response, "%d", N);

}
return response;
}

#include<ctype.h>

#include<string.h>
char * accumulate_chars( char * string ) {
int n=strlen(string);
int reslen= n *(n+1)/2;

char * res = (char * ) malloc(reslen+1);

if(res==NULL){
return NULL;
}
int indx=0;
for(int i=0;i<n;i++){
res[indx++]=toupper(string[i]);
for(int j=0;j<1;j++){
res[indx++]=tolower(string[i]);
}
if(i<n-1){
res[indx++]=' ';
}
}
res[indx]='\0';
return res;

}
#include<ctype.h>
char * accumulate_chars( char *string ) {
int i,j,len,o;
len = strlen(string);
o = (len*(len+1))/2;
int m = o*3;
char *out = malloc(sizeof(char)*m);
int idx = 0;
int c=1;
for(int i=0;i<len;i++){
char curr = toupper(string[i]);
out[idx++]=curr;
for(j=0;j<c-1;++j){
out[idx++] = tolower(curr);
}
if(i < len-1){
out[idx++]='-';
}
c++;
}
out[idx++]='\0';
return out;
}

#include <stdio.h>

int calculateRunningTotal(int n, int list_of_numbers[]) {


int product =1;
int sum = 0;
for (int i=0; i<n; i++){
product *=list_of_numbers[i];
sum +=list_of_numbers[i];
}
if (product % 2 == 0){
if (product == 0){
return 2*sum;
}
else{
return sum;
}
}
else{
if (list_of_numbers[0]==3|| list_of_numbers[2]==3){
return product+1;
}
else{
return product;
}
else{
if (list_of_numbers[0]==3|| list_of_numbers[1]==3||
list_of_number[2]==3){
return product + 1;
}
else{
return product;
}
}
}
int main() {
int n;
scanf("%d",&n);

int list_of_numbers[n];
for (int i = 0; i<n; i++) {
scanf("%d", &list_of_numbers[i]);
}

int result = calculateRunningTotal(n ,list_of_numbers);


printf("%d\n", result);

return 0;

}
}

#include <stdio.h>

int calculateRunningTotal(int n, int list_of_numbers[]) {


int s=0;
int p=1,i0=0,i3=0;
for (int i=0; i<n; i++){
if(list_of_numbers[i]==0 i0=1);
if(list_of_numbers[i]==3 i3=1);
p =p*list_of_numbers[i];
s =s+list_of_numbers[i];
}
if (p % 2 == 0){
if (p == 0){
return 2*s;
}
else{
return s;
}
}
else{
if (i3==1){
return p+1;
}
else{
return p;

}
}
}

int main() {
int n;
scanf("%d", &n);

int list_of_numbers[n];
for (int i = 0; i<n; i++) {
scanf("%d", &list_of_numbers[i]);
}

int result = calculateRunningTotal(n ,list_of_numbers);


printf("%d\n", result);

return 0;

}
}

You might also like