Monday, 1 September 2014

Sum of square program, Algorithm and Flowchart

Sum of square program, Algorithm and Flowchart

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:
Output of sum of square of any number C program
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:
flowchart for accept number and calculate sum of square
Figure: Flowchart for calculate sum of square C progra

1 comment:

  1. Casinovnj - Slots & casino: bonus codes, bonuses, list of casinos
    The 대구광역 출장안마 best Casino sites are now available on both Betika and Betika, and the 김천 출장샵 casino sites you 경상북도 출장안마 choose on 당진 출장안마 the site offers generous 수원 출장안마

    ReplyDelete