0 like 0 dislike
8.3k views

Write a program that reads a string of up to 100 characters, and if its length is less than three characters, it should force the user to enter a new one. Next, the program should read a character and check if the string contains the input character three times in a row. The program should display the position of the first triad found.

Sample input:

fg
DuplicateThis
D

Sample output: 

Not found

 

Sample input: 

Deeeply
e

Sample output:

1

Sample input: 

Deeeppply
p

Sample output:

4

 

[Exercise] Coding (C) - asked in C by (12.1k points)
ID: 22674 - Available when: Unlimited - Due to: Unlimited

edited by | 8.3k views
1 3
Called for Help

82 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<stdlib.h>

#include<string.h>



int main(){
** ** * * * ** * ** ph[100];
* ** * * * *** ** **** * findPH[1];
* * * ** *** ** findt[1];
** * * ** *** *** ** i;
** * *** * ** * ** * ** * * * * * *
* * **** ** *** ** * == ph[1] && ph[0] == ph[2]){
* * *** * ** ***** * ** * * ** *** ** ** * **** * *
** ** * * ** *** *** * ******* ** ** == findt[0] && ph[1] == findt[0] && ph[2] == findt[0]){
* * * * **** ** *** * * * * * *** * * * * ** ** * * * * * * ****** *** **** *
* * ** ** ** * * * ** ** * ** * * * *** * * * * **** 0;
*** * ***** * ** * **** ** ***** * *** ***
* ** * ** * * **** ** * **** ** * ** *
* * ** ** ** * *** * * ** ******** * * ** **** * ****** * * ** *** found");
* ** ** ** ******* *** ** *** ** * * * *** * **** ** 0;
***** **** * ** * * ***** ** ** * ******* *
*** *** * * **** ** *
***** * ** len = strlen(ph);
* ** * *** * ** ***** * < 2){
** *** *** **** * * ** * * ** * * * * * main();   
** *** * ***** **
** * *** * ** * * ** ** * *
** * ** *** ** *** ****** * ************* **
* ** * ** ** ** ** * ***** ***
* *** * * * **** *** * ** ***** * ** ******* * * == findPH[0] && ph[i+1] == findPH[0] && ph[i+2] == findPH[0]){
* * * * ** ** *** * * * *** * * *** * ** * * * ** * ** *** ****** ** *
** **** * ** * **** ** ** *** * * * ** *** *** * * *** ** ***** * 0;
* * ** * * **** * * ** * **** * * * ** *
** * * ** ** * ****** *** * * * ** ** ***
* * * **** *** ** ** found");

    

}
answered by (-134 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main (void)

{
*** *** **** * * ***** a[100];
* ** * * *** * * ** ** b;
* * *** * * * * **** i,k, count=0;


*** * * * ****
****** **** * * *
* * ** ** *** ********* **** * ** ** ** * * * * **** * * *** ** * * *
* * * ****** * *** * **
** ** ** * * * * * * *** *


****** **** *** ** ****** ** ** *** ****** **
* ** *** ** ** *** ******* i<strlen(a); i++)

    {
* * ****** *** ***** * *** * ** * * ** *******
* * ** * * * * * * * ** ** * * **
*** * * **** * * * ** * * * * **** ** *** ** **
** ** ** ** ** * * * * * *** ** ** * *** *** * **
** * * ** * * * * * ** *** ** ***** * ** ** * *
* * * *** * * * ***** ***** ****** ******* * *
** **** * ** * * * * ***** * * * *** * * ** * * * * * *** ***
* **** ** * * * * * * ****** ** ** ** * **

    }
* * * *** * * ** ** * * * *
* ** * * * *
* * ******** ****** * **** * * * * * * * ** * *

    }
* * *** * * **** *

    {
* *** * ** *** *** * ***** **** ***** **** **** ** * found");

    }

}
answered by (-367 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main (){
*** ** * * ** **** a[100],c;int i,pos=0 ,sop=-1;
* *** * ** * ***** *
* ** *** *** * ** * (pos<3){
* * ******* *** * * *** * ** * * * * ** ** ** **** ***
**** ** *** *** *** ** *** * *** ** * ** * = strlen(a);
* *** * * * **
*** ** *** * ** **** * * ****
** ** * * ********* %c",&c);
** * ** ****** ** ** ** (i=0;i<pos-3;i++){
* * * ** * ** ****** ** * ** ** **** ** * *** * ** * * * * * ((a[i]==c) && (a[i]==a[i+1]) && (a[i+1]==a[i+2]))    {
* *** *** *** * ** * * * ** * ** ** *** * * *** * ** ** ** *** ** ** * * * ** * ** * ** * ***** = i;
**** ** * *** ** * ** *** **** * **** ** * * **** * * ** * * * ** * ** * *** * *** *** **** * * *
* ****** *** *** * ** * * * **** ****** **
* * **** * * * *
* *** * * * * *
* * ** * * * * * ** * * (sop>-1){
* * ** * ***** * ** * * ***** * * ** ** * *** * * * * *
*** ** ** ** *** *
** ****** *** ** * **** **** printf("Not found");
* * * ** ** *** ** ** * *** ***** * ** * ** ***** * * *****
** ** **** *** * * **** * * **** * * * * ** * * * * ** **** *** * * * **** * * ** **** * **** ***** *** * ** * ** *


****** ** * ** * * 0 ;

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()

{



int a=0,b,c,d,e,f,i,j;

int n[100]={0};



for(i=0;i<100;i++)
* * *** * * *** ****
******* *** * * *** = getchar();
* * ***** * *** * * * ***** * **
* *** * ** *** * ** ** * *** * *** * * ** *
************ *** *** *** **** ** * * ** *** * ** ** ** * ** * * *
* * ** * * ** * **** ** *** * * ** * * *** * ******** ** ******* *
* * ******* *** ** ** * * * ** ** * **
* ** **** *** ** ** ** **** ** ** ** * *** * *
*** * * ****** *** ** *** * ****** * ****** * * * * * * * *
** * * * * * * ** * * * *** * * ******
* * * ** * ******* ** * * **


* **** * * * **** * * = getchar();



for(i=0;i<100;i++)
******* *** **** * * * * * *


** * * * ** ** * * * *** f)
** ** *** **** ** * ** * *** * * ** * ** *


*** ***** * * * ***** ** *
* * * * * * ***** ********** * * ** ***** ** * * **** *** * * * **
** ** ** ** *** ************* * * ** ******
**** ** * * * *

//if(n[i]==0)

  //  break;


* ** * * ***** ** **** * ** f)
* ** ** * ** *** ** * * ** ** ******* **** * * *

if(i==99){

printf("Not found\n");

break;

}


* ***** * * *

   // * **** *** * ** * * **** **



}
answered by (-368 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main(void){

    int i, num;

    char input, words[100];



    for(i=0; i<100; i++){
* * * * * * * **** * *** * * * *** ** **** ** ** * * &words[i]);
* * *** *** ** *** *** * ** * ***** * ***
* *** ** **** * *** * *** * ** ** * ** * * * *** **** ** *** ** *
** ** * ******* * *** ** *** * ** * ***** * * * ** * ***** * *** *** *** *** * *** * *** * *****
* ***** * * ** *** * ** * * ** ** * ****** ***** * *** ** ** * *** * * * ** * ** * * ********
* * * *** * * * * * * * * ** * * ** * ** * * * * * **
** ** ** * * *** * *** ** ****** ******* * **** * * ***** *
* *** * * *** * * * * * * * ** * ** * ** * ** * **** * ** ** *** ** *** * ** * * * ****
**** ** *** * * * *** * **** ** *** * *

    }


* * ******* *** * ** * *** ** ** ** * ** &input);


* **** * *** * ** ** * * ** i=0; i<100; i++){
* ** * ** * ****** **** * * ****** * * ** * * *****
* * ** * **** * ** * * * * ** *** * * * *** *** ** * * * * * ***** ** *****
*** ***** ***** ** * * * * * ** * * * * * ** ***
*** * ********** * *** ** * ** *** * *** * * * ** * ** **** **** * *

    }


* * * ** * * ** * * * **
* * *** ** **** * *** * * * ** ** ** * ***** ***** found\n");

    else{
* ** *** ** * *** * * ** *** ** * ******* i<100; i++){
**** * ** ** * *** ** * * *** *** ** ** * *** *** * **** * * * * * ** * *
* * * **** *** ****** ** * * ** *** *** * * **** * ** * ** * * ** *** * ** ** * ***
* * ** *** * *** * * * * * *** * *
* * ***** *** **** * ** ** ** ** **** **** ******** *** * * * * * * ** **

    }



    return 0;

}
answered by (-581 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main()

{
*** *** * ** *** * * ** * ** word[100];
** ** *** ** * ** * c;
** ******* * ** * *** count = -1, i;
* * * * **** *** **** (; ;)
** ******** * ***** **
** ** ** ** ** ** *** * ** ****** * * * * *** * * &word);
**** ***** **** ***** * ** * **** * **** (strlen(word) >= 3)
** ** * * ** * * * *** * * * * ** **** * * * ***** *** * * **
* * * * * * * *
** ** ** * * * * * ** %c", &c);
* * * * *** ****** ** *** (i = 0; i < strlen(word); i++)
* *** **** ******** *
** * ** ** * ** * * **** * * ** (word[i] == c && word[i+1] == c && word[i+1])
* * **** * ** ** ** ****** *** ** *
* *** ***** **** * ** ******* ** ** ** * * *** ****** * * * * = i;
* **** * * ***** *** * *** * * ** * ** **** * * * *** *** ** *
* * * * ** * * ** **** **** * ** ** ****
* * *** * * ** ** **
* * **** * ** ************ (count < 0)
* * * * ***** * * * * * ** * ****** found");
* ** * * * * * *
* ** ** * * ** * ** *** **** ** *** ** **** * * * * * ** * count);
* * * * ** *** ** 0;

}
answered by (-48 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()

{



int a=0,b,c,d,e,f,i,j;

int n[100]={0};


*** ***
* *** * *** * ** ** *
* ** * *** * * ** ** ***** = getchar();
* ** * **** * ** * *** * *
* ** * ** ** **** ** * *** ** ** *
* * ***** * * ** *** ** *


*** ** * * * * * * * = getchar();


** * **** ** *
** ** ** * ** * ***


****** * * ** * ** * * * *** f)
** ** * * *** ******* *** ***** * ** ** ** ** *** *


* **** **** *** * * *
* * * ** * * * ** ******** ** ** * * *** * * ***
* * * ** * * *** * * * * *** *** * * *
** **** * **** * ** * ****

//if(n[i]==0)
* ****** *****  break;


* * * ** ** * ** * * ***** f)
*** **** *** * * * * ** **** * * * *** * * * *

if(i==99){

printf("Not found\n");

break;

}


****** * ** *
* *** * ****** * * *** * *** ****



}
answered by (-368 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main()

{
* **** *** ***** * input[100];
* ** ** *** ** * ** ***** c;
* * * * ** * ** ** * count = -1, i;
**** * ** **** * * * (; ;)
** ** ** ** * * * ** *
**** * * **** ** ** * **** * ** *** * ** * ** * * ** * ** &input);
* ** * ** * * ****** * **** * **** * **** * (strlen(input) >= 3)
* * ** * ** * * * ** *** * ****** * *** * *** * ****** * **** *
* ***** ***** * * *
***** ** *** ** * ***** * * %c", &c);
* ** ** * ** ** * (i = 0; i < strlen(input); i++)
**** * * ** * ** ***
** ******* * * * * * * * ****** * * * * * * (input[i] == c && input[i+1] == c && input[i+1])
**** ** ** *** *** * * **** **** * * * **
* * * *** ** ***** * *** * * ***** ** * * * ** ** * ** * * ** **** * = i;
* *** * * * * * * * * **** * * * ** * * * ** *** * *** * ** ***
* ** **** ** ** *** ** * ** * *** * * **** ** *
** * *** * * *
**** * * * * * * * *** ** *** (count < 0)
**** *** * * * ** ***** * ** * ** *** **** found");
* *** * * * * *
******* * *** * *** ** * * ****** *** * * * * ***** ** * *** * count);
* **** **** ** *** 0;

}
answered by (20 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main(void)

{
* * * ***** * *** **** ch[100],c;
** * ** * * ** * * *** k=0,i,num=0;

   do{
**** ** ** * * *** * **** *** * * *** ** ** ** ** * ***** ** * * *** ** *


** * * ****** **** * ** **** * *

    
* * ** ** * * ** *** ** * **** * %c",&c);


* ** * * * ** ** ** *** * ******** * *
* *** ** * ** * * **
* *** * * * * ** ** **** * *** * *
** * ** *** *** * ** * *** * * * ****
* * ** ** * ****** * * * **** *** * * ** * * * *** **** * * ***


* * ** * **** *** * ** ** *** *** ****** * **
*** ***** * *** * * * * * ** * * ** ** * ******
* * ***** * * * * *** * ** * ** * * * * *
* * *** * * * * ** * **** * * ** ***** ** * * ***** * * * *
* *** ** ** ** * ** *** **** **
* *** ** ** * * * ***
* ***** * * * * * * * *** *
*** * **** * ** ***** ***** *
* *** ** **** ** ***** * **** **** *** ** * * * *** found");

    }
* * *** * * * * *** *

    {
** * ** ** * * * * **** * *** * * ** ** * * *** *** * *

    }



}
answered by (-412 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main(void){

    int i, num;

    char input, words[100];



    for(i=0; i<100; i++){
* ** * * * ** ** * *** * * * * * * **** * * ** * * &words[i]);
* *** ** ** * * ** ***** * ** *** * ** * * * *
* * * ** ** * * * * * * ** * * * ** ** * ** ** * ** * *** * ***
* * *** * **** * * ** * * * * *** ******** * * * ** * ** * ***** **** ****** * * *
*** ** ** ********* *** * * * ** **** * * *** ** * ** ** * * ** * * ** ** ** * ** *
*** * * * ****** **** ** * *** **** ******* * * * *** *** ** *
* ** * * ** * ** * * ** * ** *** * * * ** ** * * ** * * * ** **
** * * * * *** * *** ** * ** **** ** **** ** * *** * * ** * * * ***** ***
* * * ***** * ** ** ** * **** * ** ** * *

    }


* * ** * ** * *** * ** ****** *** &input);


* ** * ** *** * * * * ** i=0; i<100; i++){
** * ***** * * ***** * ** ** ** ************ * ******* *
******** ** *** *** * * ** * * *** ** *** * * * * ** * *** **
* ** ** * * * * * * ** * **** ********** * * **** *
** * ******* **** ***** ** ** * * *** ** * ** * * * * * *** *

    }


* ** * * *** * * **** * * *
* ****** ***** * ** * ** ******** * *** * *** *** * found\n");

    else{
* ** ** ** * ** * * ** ** *** ** *** * ***** i<100; i++){
* ** * **** **** *** * * * *** * *** * ** * ** *** * ** *** ***********
***** **** * * * ** ****** * **** ** *** *** *** **** * ** ** ** * ***** * *** * ** * *
** ** *** ***** * * * * ** * ** *** * ** * *
** *** * * *** * ** * ** ** * ******** **** * ** ** ***** * * * ** *

    }



    return 0;

}
answered by (-581 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.17.66
©2016-2025

Related questions

0 like 0 dislike
56 answers
[Exercise] Coding (C) - asked Mar 9, 2017 in C
ID: 22673 - Available when: Unlimited - Due to: Unlimited
| 6.3k views
0 like 0 dislike
52 answers
[Exercise] Coding (C) - asked Feb 23, 2017 in C
ID: 22017 - Available when: Unlimited - Due to: Unlimited
| 5.9k views
0 like 0 dislike
50 answers
[Exercise] Coding (C) - asked Mar 16, 2017 in C
ID: 22973 - Available when: Unlimited - Due to: Unlimited
| 5.8k views
0 like 0 dislike
90 answers
[Exercise] Coding (C) - asked Mar 16, 2017 in C
ID: 22972 - Available when: Unlimited - Due to: Unlimited
| 10.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users