Вы находитесь на странице: 1из 5

1)

/*Consider the below series:

0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8,18,9,20...

the Nth term series.

ex: N=10 -> 4

N= 8 -> 3

N=12 -> 5

N=21 -> 20

N=13 -> 12

N=15 -> 14

*/

#include <stdio.h>

int main()

int N,end;

scanf("%d",&end);

for(N=1;N<=end;N++)

if(N%2==0)

printf("%d ",(N/2)-1);

else

printf("%d ",N-1);

return 0;

2)

/*1,2,1,3,2,5,3,7,5,11,8,13,13,17......

find Nth term of the series.

N=10 ->11

N=14 ->17

N=5 -> 2

N=6 -> 5*/

#include<stdio.h>

#include<math.h>

int main()

int N,end;

scanf("%d",&end);

for(N=1;N<=end;N++)

if(N%2==0)

int count=0,num=2,flag=0,i;

while(count!=N/2)

for(i=2;i<=sqrt(num);i++)

if(num%i==0)

flag=1;

break;

if(flag==0)

count++;

num++;

flag=0;

printf("%d ",num-1);

else

if(N==1||N==3)

printf("1 ");

else

int num1=1,num2=1,num3,i;

for(i=3;i<=(N/2)+1;i++)

num3=num1+num2;

num1=num2;

num2=num3;

printf("%d ",num3);

return 0;

3)

//Look at the series below: 1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,.....

#include<stdio.h>

int main()

int num1=1,num2=2,num3,i,N;

scanf("%d",&N);

for(i=3;i<=N;i++)

num3=num1+num2;

num1=num2;

num2=num3;

printf("%d ",num3);

return 0;

4)

/*Consider the following series:

1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187.........

N -> 10 = 81 -> 3^4

N -> 8 = 27 -> 3^3

N -> 12 = 243-> 3^5

N -> 11 = 32 -> 2^5

N -> 9 = 16 -> 2^4

N -> 13 = 64 -> 2^6*/

#include<stdio.h>

#include<math.h>

int main()

int N,ans;

scanf("%d",&N);

if(N%2==0)

ans=pow(3,(N-1)/2);

printf("%d",ans);

else

ans=pow(2,(N-1)/2);

printf("%d",ans);

return 0;

4)

/*

Write a program as per the below speci

cation:

1) Accept one integer number (which will be 2 digit number) from STDIN

2) Interchange the 2 digits of this number

3) Print the resulting number to STDOUT For example, if the input value is 21,

the program will print 12 to STDOUT it can be assumed that the input value will

be such that, there will be No Zero as any of the 2 digits.

Other that the calculated numerical

output Value, no other strings/message should be printed to STDOUT

eg: 46

46%10 ->6

46/10 ->4

6*10+4

46%10*10+46/10

*/

#include<stdio.h>

int main()

int num;

scanf("%d",&num);

printf("%d",(num%10)*10+(num/10));

return 0;

5)

/*

Write a program that will replace multiple consecutive occurrences of a character

with single occurrence, and print the result in the

reverse order.

For example, if the input string is aaaaEEGccCCCxEEf , the output should be fExCcGEa

The input string of characters should be read from STDIN and the result should be

written to STDOUT Other than the required output, no other characters / string or

message should be written to STDOUT.

You can assume that the input string length will not exceed 30 characters

*/

#include<stdio.h>

int main()

char str[30],ans[30];

int ind,i=0;

scanf("%s",str);

for(ind=0;str[ind]!='\0';ind++)

if(str[ind]!=str[ind+1])

ans[i++]=str[ind];

for(ind=i-1;ind>=0;ind--)

printf("%c",ans[ind]);

return 0;