Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

plz find how this code can give an exact answer

+1 vote
asked Sep 3, 2018 by Mehdi
find nth term of series 1 1 2 3 4 9 8 27 16 81 32........
n cant exceed 30;
alternate terms consists of g.p

#include<stdio.h>
#include<math.h>
void two(int a);
void three(int b);
int main(int argc,char *argv[])
{
    int n;
n=atoi(argv[1]);
    scanf("%d",&n);
        if(n<=0)
    {
        printf("invalid term");
    }
    if(n%2==0)
    {
      if (n==2)
{
      printf("1");
}   
        three(n);
    }
   
        if(n%2!=0)
    {
        if (n==1)
{
      printf("1");
}   
        two(n);
    }
   
}
void two(int a)
{
    printf("%d",pow(2,(a/2)));
   
}

void three(int b)
{
    printf("%d",pow(3,(b/2)));
   
}

1 Answer

0 votes
answered Sep 6, 2018 by Rithik Raj (220 points)
#include<iostream.h>

void main()

{

int a[30],i;

char c;

a[0]=1;

a[1]=1;

for(i=1;i<=15;i++)

a[2*i]=2*a[2*i-2];

for(i=0;i<=15;i++)

a[2*i+1]=3*a[2*i-1];

while(c!='n')

{

cout<<"enter n";

cin>>n;

cout<<a[n-1];

cout<<"do you want another number?";

cin>>n;

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...