-->

program to get sum of 'n' integers using function.

//program to get sum of 'n' integers using function.
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{

sum();
getch();
}
void sum()
{int k=1,n,sum=0;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
      sum=sum+k;
      k++;
   }
printf("sum=%d",sum);
}

program to get/sum of all odd numbers lying between 1 to n natural numbers

//program  to get/sum of all odd numbers lying between 1 to n natural numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int k=0,n,sum=0;                         
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
      if(k%2!=0)
      {      sum=sum+k;
      }
    k++;
   }
printf("the sum=%d",sum);

getch();
}

-----------------------------
we can also write this program as shown below.
-------------------------------------
//program  to get/sum of all odd numbers lying between 1 to n natural numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n,sum=0;                         
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
            sum=sum+k;
      
    k=k+2;
   }
printf("the sum=%d",sum);
getch();
}

program to get sum of series 1 ,3,5,7,.......nth.

//program  to get sum of series 1 ,3,5,7,.......nth.
#include<stdio.h>
#include<conio.h>
void main()
{
int k,n;
int s=0;printf(enter value of 'n'\n");
scanf("%d",&n);
for(k=1;k<=n;k=k+2)
   {          
       s=s+k;
   }
printf("sum=%d,",s);
getch();
}

program to know a number is divisible by 3 and 5 both or not



//'C' program to know a number is divisible by 3 and 5 both or not
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf("enter a number\n");
scanf("%d",&x);
if(x%3==0 && x%5==0)
{
printf("it is divisible by both");
}
else
{
printf("it is not divisible by both\n");
}
getch();
}

program to know a number is even or odd using function



//program to know a number is even or odd
#include<stdio.h>
#include<conio.h>
void evenodd();
void main()
{
evenodd();
getch();
}
void evenodd()
{int x;
printf("enter a number\n");
scanf("%d",&x);
if(x%2==0)
   {
    printf("it is an even number");
    } 
else
   {
   printf("it is an odd number\n");
    }
}

program to get greatest number among three numbers

// program to get greatest number among three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
printf(“enter three numbers\n”);
scanf(“%f%f%f”,&a,&b,&c);
if(a>b &&a>c)
{
printf(“the greatest number=%f\n”,a);
}
elseif(b>a &&b>c)
{
printf(“the greatest number=%f\n”,b);
}
else
{
printf(“the greatest number=%f\n”,c);
}
getch();
}

program to get sum of 1 to n numbers

//A program  to print/display sum of 1 to n natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n,sum=0;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
      sum=sum+k;
      k++;
   }
printf("sum=%d",sum);getch();
}