HTML Tutorial || Networking Assignment || Computer Full Forms || Ms-Office Shortcut Keys || Ms-Office Notes || Number System Notes || Internet Assignment
JavaScript Tutorial || CSS Tutorial || Operating System Notes || History of Computer Assignment || Netwoking Notes || Computer Fundamentals Notes

C Program to Find Sum of all Odd Numbers b/w 1 to n ?


Q:- Write a C Program to Find Sum of all Odd Numbers b/w 1 to n ?
      Input
        #include<stdio.h>
        #include<conio.h>
        main()
  {
int num,i=1,s=0;
clrscr();
printf(“Enter a Limit of N=”);
scanf(“%d”,&num);
while(i<=num)
{
s=s+i;
i=i+2;
}
printf(“Sum of all Odd Numbers = %d”,s);
getch();
   }


Output

Enter a Limit of N = 8
Sum of all Even Numbers = 16

Comments