Q. Write a C program to accept a number from user and print the sum of square. Also write down the algorithm and draw flowchart.
Ans.
/*c program for accept number and calculate sum of square*/
#include<stdio.h>
int main()
{
int num,sum=0,i;
printf("Enter any number : ");
scanf("%d", &num);
for(i=1; i<=num; i++)
sum = sum + (i*i);
printf("Sum of square of %d = %d",num,sum);
return 0;
}
The output of above program would be:
Algorithm for accept a number from user and calculate sum of square:
[Sum of square procedure:accept number num from user, and set sum=0 and calculate sum of square.]
Step 1. Start
Step 2. Read number num
Step 3. [Initialize]
sum=0, i=1
Step 4. Repeat step 4 through 6 until i<=num
Step 5. sum=sum+(i*i)
Step 6. i=i+1
Step 7. print the sum of square
Step 8. stop
[end of loop step 4]
[end of sum of square procedure]
Flowchart for sum of square C program as following:
Ans.
/*c program for accept number and calculate sum of square*/
#include<stdio.h>
int main()
{
int num,sum=0,i;
printf("Enter any number : ");
scanf("%d", &num);
for(i=1; i<=num; i++)
sum = sum + (i*i);
printf("Sum of square of %d = %d",num,sum);
return 0;
}
The output of above program would be:
Figure: Screen shot for calculate sum of square of number C program |
Algorithm for accept a number from user and calculate sum of square:
[Sum of square procedure:accept number num from user, and set sum=0 and calculate sum of square.]
Step 1. Start
Step 2. Read number num
Step 3. [Initialize]
sum=0, i=1
Step 4. Repeat step 4 through 6 until i<=num
Step 5. sum=sum+(i*i)
Step 6. i=i+1
Step 7. print the sum of square
Step 8. stop
[end of loop step 4]
[end of sum of square procedure]
Flowchart for sum of square C program as following:
Figure: Flowchart for calculate sum of square C program |
thanks a lot...
ReplyDeletethanks ....
ReplyDeleteI want to ask how to find squares of no's from 1 to 10 in flowchart
ReplyDeletei want to flowchart of firdt 20 odd no.
ReplyDeletevery helpful to understand the concept
ReplyDeleteHow to draw flowchart for a program that display the squares of the numbers from 0 to 4 using while?can you help me. ☺
ReplyDeleteMay i know what i represents?
ReplyDeleteMay I know what i represents?
ReplyDelete