Write a program in ‘C’ to find a sum of square of odd numbers. 6m Jun 2010

By | August 17, 2016

Write a program in ‘C’ to find a sum of square of odd numbers :- 12 +32+ 52+ 72 +92+ +N2

 

Code:-

#include<stdio.h>
void main()
{
int NUM,i,j,SUM=0;
clrscr();
printf(“\nENTER INTERGER NUMBER : “);
scanf(“%d”,&NUM);
for(i=1;i<NUM+1;i++)
{
if(i%2!=0)
{
SUM=SUM+(i*i);
}
}
printf(“\nTHE SUM OF SQUARE OF ODD NOS. TILL %d NO. IS : %d”,NUM,SUM);
getch();
}

 

#include<stdio.h>
void main()
{
int NUM,i,j,SUM=0;
clrscr();
printf("\nENTER INTERGER NUMBER : ");
scanf("%d",&NUM);
for(i=1;i<NUM+1;i++)
{
if(i%2!=0)
{
SUM=SUM+(i*i);
}
}
printf("\nTHE SUM OF SQUARE OF ODD NOS. TILL %d NO. IS : %d",NUM,SUM);
getch();
}

Screen Shots:-

C_program_Add_Square_Odd

 

C_program_Add_Square_Odd_Out