Vous êtes sur la page 1sur 6

TCS NOV 2018

PAttern

Question 1 printf(“%d”,x);
}
Find the nth term of the series. }
int main()
1,1,2,3,4,9,8,27,16,81,32,243,…. {
int n;
#include<stdio.h> scanf(“%d”,&n);
#include<math.h> if(n%2==0)
int three(n) three(n/2);
{ else
int x,i; two(n/2+1);
for(i=0;i<100;i++) }
{
x=pow(3,i); Question – 2
if(i==n)
printf(“%d”,x); Link to this Question
}
} Consider the following
int two(n) series: 1,1,2,3,4,9,8,27,16,81,32,243,
{ 64,729,128,2187…
int x,i;
for(i=0;i<100;i++) This series is a mixture of 2 series –
{ all the odd terms in this series form a
x=pow(2,i); geometric series and all the even
if(i==n) terms form yet another geometric
series. Write a program to find the return 0;
Nth term in the series. }

The value N in a positive integer that Extra Questions without Solutions


should be read from STDIN. The Nth and Options that students couldn’t
term that is calculated by the remember, please add solutions in
program should be written to the comment section below –
STDOUT. Other than value of n th
term,no other character / string or 1. Given a series whose even term
message should be written to creates a separate geometric series
STDOUT. For example , if N=16, the and odd term creates another
16th term in the series is 2187, so geometric series . Prog in any
only value 2187 should be printed to language to find the nth term.
STDOUT. Where u may consider that n not
greater dan 30.
You can assume that N will not 2. 1,1,2,2,4,4,8,8,16,16 also this
exceed 30. code

#include <stdio.h> Solutions to one of the problem


#include<math.h> discussed above –

int main() { #include <stdio.h>


//code #include<conio.h>
int n; #include<math.h>
scanf(“%d”, &n); long long int power(long long int
if(n % 2 == 1) a,long long int b ){
{
int a = 1; long long int i,ans=1;
int r = 2; for(i=0;i<b;i++)
int term_in_series = (n+1)/2; {
int res = pow(2, term_in_series – 1); ans=ans*a;
printf(“%d “, res); }
} return ans;
else }
{
int a = 1; // long long int three(long long int n){
int r = 3; // return pow(3,n);
int term_in_series = n/2; // }
int res = pow(3, term_in_series – 1);
printf(“%d “, res); // long long int two(long long int n){
}
// return pow(2,n);
// }
int main() The value n in a positive integer that
{ should be read from STDIN the nth
clrscr(); term that is calculated by the
long long int i,nth,a[1000]; program should be written to
scanf(“%lld”,&nth); STDOUT. Other than the value of the
for(i=0;i<nth;i++) nth term no other characters /strings
{ or message should be written to
if(i%2==0) STDOUT.
{
a[i]=power(2,i/2); For example if n=10,the 10 th term in
} the series is to be derived from the
if(i%2==1) 9th term in the series. The 9th term is
{ 8 so the 10th term is (8/2)=4. Only
the value 4 should be printed to
a[i]=power(3,(i/2)+1); STDOUT.
}
You can assume that the n will not
} exceed 20,000.

printf(“%lld “,a[nth-1]); Code:

return 0; #include <stdio.h>


} #include<math.h>

Question 3 int main() {


//code
Link to this Question – int n;
scanf(“%d”, &n);
Consider the below series : if(n % 2 == 1)
{
0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16, int a = 1;
8 int r = 2;
int term_in_series = (n+1)/2;
This series is a mixture of 2 series all int res = 2 * (term_in_series – 1);
the odd terms in this series form printf(“%d “, res);
even numbers in ascending order }
and every even terms is derived from else
the previous term using the formula {
(x/2) int a = 1;
int r = 3;
Write a program to find the nth term int term_in_series = n/2;
in this series.
int res = term_in_series – 1; 1. These three words will be read
printf(“%d “, res); one at a time, in three separate
} line
2. The first word should be changed
return 0; like all vowels should be replaced
} by $
3. The second word should be
Solution not Available in other changed like all consonants
languages as of now- Please add should be replaced by #
in comments 4. The third word should be changed
like all char should be converted
Question 4 to upper case
5. Then concatenate the three words
0,0,2,1,4,2,6,3,8,4,10,5,12,6…. and print them
Link to this Question Other than these concatenated word,
no other characters/string should or
#include<stdio.h> message should be written to
int main() STDOUT
{
int i=3,n; For example if you print how are you
printf(“enter nth term”); then output should be h$wa#eYOU.
scanf(“%d”,&n);
int a[n+1]; You can assume that input of each
a[1]=0; word will not exceed more than 5
a[2]=0; chars
while(i<=n)
{ Write Code for this
if(i%2==0)
a[i]=a[i-2]+1; #include<stdio.h>
else #include<stdlib.h>
a[i]=a[i-2]+2; #include<string.h>
i++; int main()
} {
printf(“%d”,a[n]); char *str1=malloc(sizeof(char)*256);
} char *str2=malloc(sizeof(char)*256);
char *str3=malloc(sizeof(char)*256);
Question 5 printf(“ENter 3 words : “);
scanf(“%s%s%s”,str1,str2,str3);
Link to this Questions
int p1=strlen(str1);
1. The program will recieve 3 English int p2=strlen(str2);
words inputs from STDIN int p3=strlen(str3);
for(int i=0;i<p1;i++) 3.term(N)=term(N-1)+term(N-2)for
{ N>2
if(str1[i]==’a’||str1[i]==’e’||str1[i]==’i’||s
tr1[i]==’o’||str1[i]==’u’) Write a program to find the Nth term
{ in this series .the value N is a
str1[i]=’$’; positive integer that should be read
} from STDIN.the Nth term that is
} calculated by the program should be
for(int i=0;i<p2;i++) written to STDOUT,other than the
{ value of nth term no other characters
if(str2[i]!=’a’ && str2[i]!=’e’ && /strings and messages should be
str2[i]!=’i’ && str2[i]!=’o’ && written to STDOUT.
str2[i]!=’u’)
{ For example if N =15,the value of
str2[i]=’#’; 15thn term is 987 which is the sum of
} 13th and 14th terms . You can
} assume that the value of n will not
for(int i=0;i<p3;i++) exceed 30
{
str3[i]=str3[i]-32; Ans:
}
#include <stdio.h>
printf(“\n%s”,str1);
printf(“\n%s”,str2); int main() {
printf(“\n%s”,str3);
//code int n;
return 0;
scanf(“%d”, &n);
}
if(n == 1)
Question 7
{
Link to this code is here
printf(“1”);
look at the series below:
1,2,3,5,8,13,21,34,55,89,144,233,37 }
7,610,987,…..
else if(n ==2)
This series is formed as below:
1.term(1)=1 {

2.term(2)=2 printf(“2”);

}
else count=1;

{ while(a[i]==a[i+1])

int t1=1, t2=2, nth_term; for(int i = 3; i {


<=n; i++)
i++;
{
count++;
nth_term = t1 + t2; t1 = t2;
}
t2 = nth_term;
printf(“%c%d”,a[i],count);
}
}
printf(“%d”, nth_term);
return 0;
}
}
return 0;

Question 8

aaaabbBccdee change to
a4b2B1c2d1e2

Write code for this in the comment


section below –

int main()

char a[100];

int i,count=0;

scanf(“%s”,a);

for(i=0;a[i]!=’\0′;i++)

Vous aimerez peut-être aussi