Skip to content

Commit

Permalink
addeANS.c
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaanilkumar committed Jun 29, 2020
1 parent 50bc7a8 commit 0c9855a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions C/exam/answer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Name: Adithya A
Roll No: 03
Class : CS2B
*/
//Input any string from the user and find the first occurrence of a given character in the string.
#include <stdio.h>
#include <string.h>
int first_occurance(char str[1000],char c){
int i = 0;
for(i=0;i<strlen(str);i++){
if(c==str[i]){
return i;
}
}
return -1;
}
void main(){
char str[50], c;
printf("Enter the string :\n");
scanf("%s", str);
printf("Enter character to be searched for :\n");
scanf("%c", &c);
int index = first_occurance(str,c);
if(index==-1){
printf("Character Not Found");
}
else{
printf("character position is at %d \n", index+1);
printf("character index is at %d \n", index);
}
}
Binary file added C/exam/answer.exe
Binary file not shown.

0 comments on commit 0c9855a

Please sign in to comment.