Assignment 2
Assignment 2
a. sum=0;
while(x>0){
if(x%2==0){
x++;
sum +=x%10;
}else
sum +=x%10 +1;
x=x/10
}
return sum;
c. int sum= 0;
for (i = 1; i <= n * n - 10; i++)
for (j = 1; j <= i; j ++)
sum += j;
d. int sum = 0;
for (i = 1; i <= n; i *= 2)
for (j = 1; j <= i; j++)
sum += j;
e. int counter = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j += i)
counter++;
1
HiLCoE School of Computer Science and Technology
counter++;
}
g. int count = 0;
void f(int n) {
if (n == 0) return;
for (int i = 0; i < n; i++)
count++;
f(n-1);
}
h. int sum = 0;
void f(int n) {
if (n == 0) return;
sum += 1;
f(n-1);
f(n-1);
}
i. int counter=0;
void f(int n) {
if (n == 0) return;
for (int i = 0; i < n; i++)
counter++;
for (int i = 0; i < 4; i++)
f(n/4);
}
Important:
It’s a group assignment (max. of 6 members and min. of 4 members)
Each member of the group must participate on the work.
Exchange of any answer between groups is considered as a
cheating. Both group will not receive any credit from the
assignment
Finally, submit your assignment question with answers in pdf.
Assignment due date: March 16, 2024 12 p.m.