[go: up one dir, main page]

0% found this document useful (0 votes)
16 views2 pages

Activity Find Repeat Letters in A Word

The document contains two C programming code snippets. The first snippet prints the ASCII value of a character entered by the user. The second snippet finds and counts the number of repeated letters in a word input by the user.

Uploaded by

Fredy Criollo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Activity Find Repeat Letters in A Word

The document contains two C programming code snippets. The first snippet prints the ASCII value of a character entered by the user. The second snippet finds and counts the number of repeated letters in a word input by the user.

Uploaded by

Fredy Criollo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-----------------------------------------------------------------------------------

---------------------------------------

Code to print the ASCII value of a variable:

#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);

// %d displays the integer value of a character


// %c displays the actual character
printf("ASCII value of %c = %d", c, c);

return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------

Activity: find repeat letters in a word

#include <stdio.h>

int main(){
char word[51];
scanf("%s", word);
int n=0;
int i=0;
int j=0;
int swap=0;
int counter=0;
int updt=0;

while (word[n] != '\0'){


n++;
}

for (j=0; j<n-1; j++)


{
for (i=0; i<n-1; i++)
{
if (word[i] > word[i+1])
{
swap=word[i+1];
word[i+1]=word[i];
word[i]=swap;
}
}
}

i=0;
while (word[i] != '\0' )
{
if (word[i]==word[i+1]){
updt++;
}else{

if(updt>=1)
{
counter++;
}

updt=0;
}

i++;
}
printf ("%d", counter);
return 0;
}

You might also like