In this post students will be able to find easiest solutions to the questions that will help them understand the course concepts in depth and as well help them achieve their academic target.
Page Contents
1.Draw the flowchart for finding largest of three numbers and write an algorithm and explain it.
Algorithm:
1.Start
2.Enter three variables X,Y,Z.
3.If X>Y and X>Z, print X is the greatest
4.Otherwise, If Y>X and Y>Z, print Y is the greatest
5.Otherwise, print Z is the greatest
6.Stop
Flowchart:

The algorithm starts by inputting three numbers A, B, and C. It then checks if A is greater than B, and if so, it checks if A is greater than C.
If A is greater than C, then A is the largest number, and it is displayed as the output. If A is not greater than C, then C is the largest number, and it is displayed as the output.
|
If A is not greater than B, then the algorithm checks if B is greater than C. If so, then B is the largest number, and it is displayed as the output. If not, then C is the largest number, and it is displayed as the output. The algorithm then ends.
2.Write a program to find sum and average of first n natural number.
Program:
#include<stdio.h>
int main(){
int n,i,sum=0;
float average;
printf("Enter a positive integer n: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
sum += i;
}
average = (float)sum / n;
printf("The sum of the first %d natural numbers is %d\n", n, sum);
printf("The average of the first %d natural numbers is %.2f\n", n, average);
return 0;
}
- The user is prompted to enter a positive integer n using the
printf()
function and thescanf()
function is used to read the user input and store it in the variablen
. - A variable called
sum
is initialized to 0. - A
for
loop is used to iterate from 1 to n (inclusive). For each iteration, the loop adds the current number (i) to thesum
variable. - Once the loop is finished, the average is calculated by dividing the sum by n and storing the result in a variable called
average
. Note that we castsum
to a float before dividing byn
to ensure that the result is a floating-point number. - The sum and average are printed to the console using the
printf()
function.
3.Write an algorithm, flowchart and program to find whether a given number is zero, positive or negative.
Algorithm:
- Start
- Initialize a variable
num
to store the input number. - Read the value of
num
from the user. - If
num
is equal to zero, print “The number is zero.” and stop. - If
num
is greater than zero, print “The number is positive.” and stop. - If
num
is less than zero, print “The number is negative.” and stop. - Stop.
FLOWCHART:

Program:
#include<stdio.h>
int main() {
int num;
printf("Enter a number:");
scanf("%d",& num);
if (num==0){
printf("the number is zero");
}
else if(num>0){
printf("the number is positive");
}
else{
printf("the number is negative");
}
return 0;
}