Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Write a program that print word in new line when get white space.
- #include <stdio.h>
- int main(){
- char s[101];
- while(scanf(" %s", s)!=EOF && s[0]!='#'){ /// if input contains #, it will break the loop. Remove if needed
- printf("%s\n", s);
- }
- return 0;
- }
- 2. Write a program that print word in new line after removing extra space.
- /// duplicate
- 3. Write a program that will count the number of white space in the input string.
- #include <stdio.h>
- int cntSpace(char *s){
- int cnt=0, i;
- for(i=0; s[i]!='\0'; i++){
- if(s[i]==' ') cnt++;
- }
- return cnt;
- }
- int main(){
- char s[1001];
- scanf("%[^\n]", s); /// you can use gets(s) as well which is deprecated from standard
- printf("%d\n", cntSpace(s));
- return 0;
- }
- 4. Write a program to find ascii code of a character
- #include <stdio.h>
- int main(){
- char c;
- scanf("%c", &c);
- printf("%d\n", c);
- return 0;
- }
- 5. Write a program to copy string without strcpy.
- #include <stdio.h>
- #include <string.h>
- void copy(char *b, char *a, int len){
- int i;
- for(i=0; i<len; i++){
- b[i]=a[i];
- }
- b[i]='\0';
- }
- int main(){
- int sz=101; /// maximum string size, change it as required
- char ar[sz], br[sz];
- scanf("%s", ar); /// use gets(ar) [non-standard way] or scanf("%[^\n]", s) to scan a whole line
- int len=strlen(ar);
- copy(br, ar, len);
- printf("%s\n", br);
- return 0;
- }
- 6. Write a program to check input is an alphabet or number or special character.
- #include <stdio.h>
- bool isAlpha(char ch){
- if(ch > 'Z') ch = ch - 'a' + 'A';
- return (ch >= 'A' && ch <= 'Z');
- }
- bool isDigit(char ch){
- return ( ch >= '0' && ch <= '9' );
- }
- int main(){
- char c;
- scanf("%c", &c);
- if(isDigit(c)) printf("Digit\n");
- else if(isAlpha(c)) printf("Alphabet\n");
- else printf("Special character\n");
- return 0;
- }
- 7. Write a program to find length of string and number of white space in the input string.
- #include <stdio.h>
- int cntSpace(char *s){
- int cnt=0, i;
- for(i=0; s[i]!='\0'; i++){
- if(s[i]==' ') cnt++;
- }
- return cnt;
- }
- int strLen(char *s){
- int cnt=0, i;
- for(i=0; s[i]!='\0'; i++) cnt++;
- return cnt;
- }
- int main(){
- char s[101];
- scanf("%[^\n]", s); /// you can use gets(s) as well which is deprecated from standard
- printf("String length= %d\n", strLen(s));
- printf("Number of whitespaces= %d\n", cntSpace(s));
- return 0;
- }
- 8. Write a program to make a simple calculator that takes only number as input.
- /// need to be more specific, is it just an integer input output or something else?
- 9. Write a program that will count number of vowel, consonant and digit and whitespace.
- #include <stdio.h>
- bool isVowel(char c){
- if(c>'Z') c=c-'a'+'A';
- if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U') return 1;
- return 0;
- }
- bool isCons(char c){
- if(c>'Z') c=c-'a'+'A';
- if(c>='A' && c<='Z') return 1;
- return 0;
- }
- bool isDig(char c){
- return ( c>='0' && c<='9' );
- }
- int main(){
- int i=0, v=0, c=0, d=0, sp=0;
- char s[101];
- scanf("%[^\n]", s); /// you can use gets(s) as well which is deprecated from standard
- for(i=0; s[i]1='\0'; i++){
- if(isDig(s[i])) d++;
- else if(isVowel(s[i])) v++;
- else if(isCons(s[i])) c++;
- else if(s[i]==' ') sp++;
- }
- printf("Vowels= %d, Consonants= %d, Digits= %d, Whitespaces= %d\n", v, c, d, sp);
- return 0;
- }
- 10. Write a program that will take a string as input and print whether this is a comment or not.
- /// What's the definition of comment?
- 11. Write a program that will take a line as input and print the line with removing extra space.
- #include <stdio.h>
- int main(){
- char s[101];
- while(scanf("%s", s)!=EOF && s[0]!='#'){ ///used # as ending line, change/remove as required
- printf("%s", s);
- }
- return 0;
- }
- 12. Write a program for symbol table.
- /// what's the definition of symbol table?
- 13. Write a program for identify token (ex: find operator)
- /// need more detail about it
- 14. Write a program to find the first & follow of grammar.
- /// need more detail, it's totally unclear to me
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement