Showing posts with label n. Show all posts
Showing posts with label n. Show all posts
Wednesday, February 11, 2015
C program to raise any number x to a positive power n
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,n,result;
clrscr(); //to clear the scrren
printf("Enter value of x and n:");
scanf("%d%d",&x,&n);
result=pow(x,n);
printf("
Result=%d",result);
getch(); //to stop the screen
}
C Program to calculate and print the sum of even and odd integers of the first n natural numbers
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,sumeven=0,sumodd=0;
cout<<"Enter value of n:";
cin>>n;
for(i=1;i<=n;++i)
{
if(i%2==0)
sumeven+=i;
else
sumodd+=i;
}
cout<<"
Sum of even Numbers is "<<sumeven;
cout<<"
SUm of odd Numbers is "<<sumodd;
getch();
}
#include<conio.h>
void main()
{
clrscr();
int n,i,sumeven=0,sumodd=0;
cout<<"Enter value of n:";
cin>>n;
for(i=1;i<=n;++i)
{
if(i%2==0)
sumeven+=i;
else
sumodd+=i;
}
cout<<"
Sum of even Numbers is "<<sumeven;
cout<<"
SUm of odd Numbers is "<<sumodd;
getch();
}
Subscribe to:
Posts (Atom)