Previous Next
0 / 23
Module DEMO-32-108DEMO-C-32

First Occurrence

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program that finds the index of the first occurrence of a specific character in a string. Print -1 if the character is not found.

Constraints

Max string length: 100

Input Format

Input:

C S

Output Format

Output:

Index

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
z uber
-1
Character z is found at index -1 in uber.
Sample #2
Public sample
t packet
5
Character t is found at index 5 in packet.
Sample #3
Public sample
t date
2
Character t is found at index 2 in date.
Sample #4
Public sample
i quince
2
Character i is found at index 2 in quince.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings