Fibonacci series
Ques-Given the value of 'n' , write a recursive routine in C to print the first 'n' elements of the Fibonacci series.
input format-
value of 'n'
output format-
fibonacci series of 'n' terms, each term separated by a space.
C code-
#include<stdio.h>
main()
{
int a,i,s=0,m=1,n=0;
scanf("%d",&a);
for(i=1;i<=a;i++)
{
if(i==1)
{
printf("%d ",s);
continue;
}
if(i==2)
{
printf("%d ",m);
continue;
}
n=s+m;
s=m;
m=n;
printf("%d ",n);
}
}
Reversed string-
Ques-Enter any string and find the reverse of the string. for example-abc should be printed as cba.
C code-
#include<stdio.h>
#include<string.h>
main()
{
int i=0,j=0;
char s[20],temp;
scanf("%s",&s);
j=strlen(s)-1;
i=0;
while(i<j)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
i++;
j--;
}
printf("%s",s);
}
Cyclic Right Shift-
Ques-enter the number of elements then enter that number of elements and then enter the number of times you want the letters to be shifted.
example-number of elements-6
1,2,3,4,5,6
number of times shifted-2
the new shifted series-5,6,1,2,3,4
C code-
#include<stdio.h>
main()
{
int a,i,s[200],c=0,m,temp;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&s[i]);
}
scanf("%d",&m);
do
{
for(i=a-1;i>0;i--)
{
temp=s[i];
s[i]=s[i-1];
s[i-1]=temp;
}c++;
}while(c<m);
for(i=0;i<a;i++)
{
printf("%d",s[i]);
}
}
Second Smallest-
ques-given the set of numbers find out the second smallest number present in the set.
example-number of elements-5
elements-1,4,5,6,3
second smallest-3
C code-
#include<stdio.h>
#include<string.h>
main()
{
int a=0,i=0,temp,j=0,s[200];
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&s[i]);
}
for(i=0;i<a;i++)
{
for(j=i+1;j<a;j++)
{
if (s[i]>s[j])
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
printf("%d",s[1]);
}
leaders of elements
Ques-Given a set of 'n' elements in an order.identify all the leaders and print them .An element is said to be a leader if all the elements to its right are smaller than it .For example-if the elements are 12,13,16,7,10 then there is only one leader -16.if there are no leaders in a given set of elements then print 'No Leaders'.
input format-
number of numbers in a given set 'n'
element-1
element-2
.....
element-n
output format-
elements that are leaders else print 'No leaders' when there is no leader.
C code-
#include<stdio.h>
main()
{
int n,i,j,d=0;
scanf("%d",&n);
int s[n];
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
}
for(i=0;i<n-1;i++)
{
int c=0;
for(j=i-1;j<n;j++)
{
if (s[i]>s[j]
c++;
}
if (c==n-(i+1))
{
printf("\n%d",s[i]);
d++;
}
}
if (d==0)
printf("No leaders");
}
Harrah's Lake Tahoe Casino and Hotel - Mapyro
ReplyDeleteHARRAH'S LAKE TAHOE CASINO 광주 출장마사지 AND HOTEL in Stateline NV at 1 정읍 출장안마 Highway 50, Stateline 89449, US. Find reviews and discounts for AAA/AARP 동해 출장샵 members, seniors, Check In: 여주 출장샵 3:00pmNon Smoking Rooms: 1600Check Out: 12:00amRoom Windows: Windows Do Open Rating: 4.5 · 밀양 출장안마 12,615 votes