What you said? And what you get?
Answer:
For loop Version:
#include <stdio.h>
int main()
{
int number, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &number);
for (int i = 0; i <= number; i++) {
if(number == 0)
break;
sum += number;
printf("Enter a positive integer: ");
scanf("%d", &number);
}
printf("Sum is: %d", sum);
return 0;
}
- - - - -
While Loop Version:
#include <stdio.h>
int main()
{
int number, sum = 0, i = 0;
printf("Enter a positive integer: ");
scanf("%d", &number);
while (number != 0) {
sum += number;
printf("Enter a positive integer: ");
scanf("%d", &number);
}
printf("Sum is: %d", sum);
return 0;
}
Do-while Loop Version:
#include <stdio.h>
int main()
{
int number, sum = 0, i = 0;
do {
printf("Enter a positive integer: ");
scanf("%d", &number);
sum += number;
} while (number != 0);
printf("Sum is: %d", sum);
return 0;
}
Explanation:
- Initialize the variables
- Ask the user for the numbers until the user enters 0
- Calculate and print the sum
Answer:
The program to this question can be given as:
Program:
#include <stdio.h> //include header file.
int main() //defining main method
{
char i,j; //defining variable
for (i='a'; i<='e'; i++) //outer loop for column
{
for (j='a'; j<='e'; j++) //inner loop for row
{
printf("%c%c\n",i,j); //print value
}
}
return 0;
}
Output:
image.
Explanation:
- In the above C language program, firstly a header file is included. Then the main method is defined in this, a method contains a char variable that is "i and j". This variable is used in for loop, that is used to print the pattern.
- To print the following patter two for loop is used the outer loop is used for print columns and the inner loop prints row.
- In C language to print character, we use "%c" inside a loop print function is used, that prints characters.
Answer:
C. Use the SOAP API to maintain the related SObject_share records
Answer:
Sequence of popped values: h,s,f.
State of stack (from top to bottom): m, d
Explanation:
Assuming that stack is initially empty. Suppose that p contains the popped values. The state of the stack is where the top and bottom are pointing to in the stack. The top of the stack is that end of the stack where the new value is entered and existing values is removed. The sequence works as following:
push(d) -> enters d to the Stack
Stack:
d ->top
push(h) -> enters h to the Stack
Stack:
h ->top
d ->bottom
pop() -> removes h from the Stack:
Stack:
d ->top
p: Suppose p contains popped values so first popped value entered to p is h
p = h
push(f) -> enters f to the Stack
Stack:
f ->top
d ->bottom
push(s) -> enters s to the Stack
Stack:
s ->top
f
d ->bottom
pop() -> removes s from the Stack:
Stack:
f ->top
d -> bottom
p = h, s
pop() -> removes f from the Stack:
Stack:
d ->top
p = h, s, f
push(m) -> enters m to the Stack:
Stack:
m ->top
d ->bottom
So looking at p the sequence of popped values is:
h, s, f
the final state of the stack:
m, d
end that is the top of the stack:
m