Series Printing coding 5
CODE NO:- 17
Q)Write a program to display the sequence 1,4,9,16,25,36,49......
#LOGIC
Here we have to raise ith index to power 2.
For example: 1^1=1, 2^2=4, 3^2=9 and so on.
#Program (In C):
In C language we use ' // ' for Single line comment and /*---*/ for multi line comment
#include<stdio.h> // for i/p and o/p
#include<math.h> // for pow() function
int main()
{
int n,i,a;
printf("\nenter no.of terms:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=pow(i,2);
printf("%d, ",a);
}
return 0;
}
We got this output by using DEV C++ (IDE)
Link: For other series printing problems
Q)Write a program to display the sequence 1,4,9,16,25,36,49......
#LOGIC
Here we have to raise ith index to power 2.
For example: 1^1=1, 2^2=4, 3^2=9 and so on.
#Program (In C):
In C language we use ' // ' for Single line comment and /*---*/ for multi line comment
#include<stdio.h> // for i/p and o/p
#include<math.h> // for pow() function
int main()
{
int n,i,a;
printf("\nenter no.of terms:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=pow(i,2);
printf("%d, ",a);
}
return 0;
}
We got this output by using DEV C++ (IDE)
Link: For other series printing problems
Good
ReplyDelete