Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tejasvi #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Tejasvi/binary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
int main(){
int i,n,k;
int a=0;
printf("enter no of terms in array:");
scanf("%d",&n);
int x[n];

printf("enter the number in ascending order\n");
for(i=0;i<n;i++){ //taking input in array
scanf("%d",&x[i]);
}

printf("your array is:");
for(i=0;i<n;i++){ //output in array
printf("%d",x[i]);
}

printf("\n");

int low=0; //binary search
int high=n-1;
int mid=(low+high)/2;
printf("enter no. to be searched:");
scanf("%d",&k);
while(low<=high){
if(x[mid]>k){
high=mid-1;
mid=(low+high)/2;
}
else if(x[mid]<k){
low=mid+1;
mid=(low+high)/2;
}
else if(x[mid]==k){
printf("k is found at index %d",mid);
a++;
break;
}
}
if(a==0){
printf("number not found");
}
}
25 changes: 25 additions & 0 deletions Tejasvi/bubble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
int main(){
int i,j,n,temp;
printf("enter number of terms:");
scanf("%d",&n);
int x[n];
for(i=0;i<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
if (x[j]>x[j+1]){
//swap x[j] to x[j+1]
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
printf("sorted\n");
for(i=0;i<n;i++){
printf("%d\n",x[i]);
}

}
21 changes: 21 additions & 0 deletions Tejasvi/countvow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
int main(){
int i,n;
int countvow,countcons;
printf("no of letters in the word:\n");
scanf("%d",&n);
char x[n];
printf("enter your word:");
//gets(x);
scanf("%s",&x);
for(i=0;i<n;i++){
if(x[i]=='a'|| x[i]== 'e' || x[i]=='i' || x[i]=='o' || x[i]=='u'){
countvow++;
}
else{
countcons++;
}
}
printf("no of vowels:%d\n",countvow);
printf("no of consonants:%d",countcons);
}
21 changes: 21 additions & 0 deletions Tejasvi/fib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
int fibo(int,int,int);
int fibo(int n,int a,int b){
if(n==0){
return a;
}
else if(n==1){
return b;
}
else{
return fibo(n-2,a,b)+fibo(n-1,a,b);
}
}
int main(){
int a,i,c,d;
scanf("%d",&a);
scanf("%d %d",&c,&d);
for(i=0;i<a;i++){
printf("%d ",fibo(i,c,d));
}
}
25 changes: 25 additions & 0 deletions Tejasvi/linear.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
int main(){
int i,n,k,a=0;
printf("enter no of terms in array:");
scanf("%d",&n);
int x[n];
for(i=0;i<n;i++){ //taking input in the array
scanf("%d",&x[i]);
}
printf("enter no to be searched:"); //taking the no to be searched
scanf("%d",&k);
for(i=0;i<n;i++){ //searching the number taken above
if(k==x[i]){
a=i;
break;
}
}
if(a==0){ //a is taken because not found was printing repeatetively
printf("not found");
}
else{
printf("found at index %d",a);
}

}
19 changes: 19 additions & 0 deletions Tejasvi/pallin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
int main(){
int n,r,c;
int sum=0;
printf("enter no n:");
scanf("%d",&n);
c=n;
while(n>0){
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(sum==c){
printf("yes");
}
else{
printf("no");
}
}