//program to print/display 1,8,27... to 10th term.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n;
while(k<=10)
{
printf("%d,",k*k*k);
k++;
}
getch();
}
second method:
//program to print/display 1,8,27... to 10th term.
#include<stdio.h>
#include<conio.h>
#include<math.h>void main()
{
int k=1,n;
while(k<=10)
{
printf("%d,",pow(k,3);// it means get power 3 of k. pow() is a function stored in 'math.h'
k++;
}
getch();
}
note:
If you want to display 'n' number of times then simply put
int n;declare this.
printf("enter value of n\n");
scanf("%d",&n)
put above two lines before while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n;
while(k<=10)
{
printf("%d,",k*k*k);
k++;
}
getch();
}
second method:
//program to print/display 1,8,27... to 10th term.
#include<stdio.h>
#include<conio.h>
#include<math.h>void main()
{
int k=1,n;
while(k<=10)
{
printf("%d,",pow(k,3);// it means get power 3 of k. pow() is a function stored in 'math.h'
k++;
}
getch();
}
note:
If you want to display 'n' number of times then simply put
int n;declare this.
printf("enter value of n\n");
scanf("%d",&n)
put above two lines before while loop.
No comments:
Post a Comment