FOR 'C'
#include <stdio.h>
#include <stdlib.h>
void main(){
int n,i=0,j,p=0;
char punctuation[] = {'!', '"', '#', '$', '%', '&','(', ')', '*', '+', ',', '-','.', '/', ':', ';', '<', '=','>', '?', '@', '[', '\\', ']','^', '_', '`', '{', '|', '}', '~'};
printf("Enter the lenght of string you want to enter : ");
scanf("%d",&n);
getchar();
n++;
char *s=(char*)malloc(n*sizeof(char));
printf("Enter the string : ");
fgets(s,n,stdin);
while (s[i]!='\0'){
for (j=0;j<31;j++){
if (s[i]==punctuation[j]){
p++;
}
}
i++;
}
printf("-------------------------------------------------------------------------------------------------------------------------------------");
printf("\nThere are total %d punctuation marks in the string you entered",p);
printf("\n-------------------------------------------------------------------------------------------------------------------------------------");
}
FOR 'PYTHON'
punctuation = ['!', '"', '#', '$', '%', '&', "'",'(', ')', '*', '+', ',', '-','.', '/', ':', ';', '<', '=','>', '?', '@', '[', '\\', ']','^', '_', '`', '{', '|', '}', '~']
a=input("Enter the string : ")
p=0
for i in range(len(a)):
for j in range(len(punctuation)):
if a[i]==punctuation[j]:
p+=1
print("-------------------------------------------------------------------------------------------------------------------------------------")
print("There are",p,"punctuation marks in the string")
print("-------------------------------------------------------------------------------------------------------------------------------------")