1) What Does The Following Program Print? # include<stdio.h> int sum(int number)
ID: 3547233 • Letter: 1
Question
1) What Does The Following Program Print?
# include<stdio.h>
int sum(int number);
int main(void)
{
int x = 3;
printf("The sum of all positive integers (<= %d) is %d. ",x,sum(x));
return 0; }
int sum(int number) {
int tsum;
printf("test %d at the beginning ", number); if(number <= 1)
return 1;
tsum = number + sum(number - 1); printf("test %d at the end ", number); return tsum;
}
2) Write a function to check whether two strings are anagrams or not, where string is assumed to consist of low case letters only. Two strings are said to be anagrams of each other if the letters from one string can be rearranged to form the other string. From the definition, it is clear that two strings are anagrams if all letters in both strings appear the same number of times.
For example "abc" and "cab" are anagram strings. However,
Explanation / Answer
Answer 1.
test 3 at the beginning
test 2 at the beginning
test 1 at the beginning
test 2 at the beginning
test 3 at the end
The sum of all positive integers (<= 3) is 6.
Answer 2.
bool check(char a[], char b[]){
int p = sizeof(a), q = sizeof(b), j;
if(p != q) return false;
int arr1[26], arr2[26];
for(j = 0; j < 26; j++){
arr1[j] = 0;
arr2[j] = 0;
}
for(j = 0; j < p; j++){
int k = a[j];
arr1[k - 97]++;
}
for(j = 0; j < q; j++){
int k = b[j];
arr2[k - 97]++;
}
for(j = 0; j < 26; j++){
if(arr1[j] != arr2[j]) return false;
}
return true;
}
Answer 3.
3
23
10 3 23
Answer 4.
4, -8, 7,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.