Problem statement:- Program to Find all non repeated characters in a string.
Example:-
Input: Given
String=C STRING PROGRAM
Output: C S T I N P O A M
Input: Given
String=string question
Output:r g q u e o
Sample Input/Output:-
Data requirement:-
Input Data:- str
Output Data:-ch
Output Data:-ch
Additional Data:- i, arr
Program in C
Here is the source code of the C Program to Find all non repeated characters in a string.
Code:
#include<stdio.h>
#include<string.h>
main()
{
char str[30];
printf("Enter your String:");
scanf("%[^\n]",str);
int arr[256]={0},i;
for(i=0;i<strlen(str);i++)
{
if(str[i]!=' ')
arr[str[i]]++;
}
char ch=' ';
printf("All Non-repeating character in a given string is:");
for(i=0;i<strlen(str);i++)
{
if(arr[str[i]]==1){
ch=str[i];
printf("%c ",ch);
}
}
}
Enter your String:C STRING PROGRAM
All Non-repeating character in a given string is:C S T I N P O A M
Program in C++
Here is the source code of the C++ Program to Find all non repeated characters in a string.
Code:
#include<iostream>
#include <cstring>
using namespace std;
main()
{
string str;
cout<<"Enter your String:";
getline(cin,str);
int in,len=0,i;
for(in=0;str[in]!='\0';in++)
{
len++;
}
int arr[256]={0};
for(i=0;i<len;i++)
{
if(str[i]!=' ')
arr[str[i]]++;
}
char ch=' ';
cout<<"All Non-repeating character in a given string is:";
for(i=0;i<len;i++)
{
if(arr[str[i]]==1){
ch=str[i];
cout<<ch<<" ";
}
}
}
Enter your String:string question
All Non-repeating character in a given string is:r g q u e o
Program in Java
Here is the source code of the Java Program to Find all non repeated characters in a string.
Code:
import java.util.Scanner;
public class AllNonRepeatingCharacter {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str;
System.out.println("Enter your String:");
str=cs.nextLine();
int i;
int arr[]=new int[256];
for(i=0;i<str.length();i++)
{
if(str.charAt(i)!=' ')
arr[str.charAt(i)]++;
}
char ch=' ';
System.out.print("All Non-repeating character in a given string is:");
for(i=0;i<str.length();i++)
{
if(arr[str.charAt(i)]==1){
ch=str.charAt(i);
System.out.print(ch+" ");
}
}
cs.close();
}
}
Enter your String:
csinfocs
All Non-repeating character in a given string is:i n f o
Program in Python
Here is the source code of the Python Program to Find all non repeated characters in a string.
Code:
str=input("Enter Your String:")
arr=[0]*256
for i in range(len(str)):
if str[i]!=' ':
num=ord(str[i])
arr[num]+=1
ch=' '
print("All Non-repeating character in a given string is: ",end="")
for i in range(len(str)):
if arr[ord(str[i])] ==1:
ch=str[i]
print(ch,end=" ")
Enter Your String:python string
All Non-repeating character in a given string is: p y h o s r i g
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box