13
#include<stdio.h> #include<conio.h> #include<string.h> void main() { int first,last,flag=1; char str[100]; clrscr(); printf("Enter number to get to check wheather palindrome or not"); gets(str); first=0; last=strlen(str)-1; printf("%d",first); printf("%d",last); while(first<=last) { if(str[first]!=str[last]) flag=0; first++; last--; } if(flag==1) { clrscr(); printf("this is palindrome"); getch(); } else { clrscr(); printf("sorry this is not a palindrome"); getch(); } }
Here i have declared the methods as static and passed the required variables to it. These variables can also be made implemented as data members and methods can be used to operate on them.#includeusing namespace std;class check{public:static void armgstrong(int n){int temp = n, num=0,digit;while( temp!=0){digit = temp%10;num = num*10 + digit*digit*digit;temp /= 10;}if( num == n)printf("%d is Armstrong number\n", n);elseprintf("%d is not Armstrong number\n", n);}static void palindrome( char str[]){int i=0, j=strlen(str)-1, flag = 0;for( i=0, j = strlen(str)-1; i < j && !flag; i++, j--){if( str[i] != str[j])flag = 1;}if( !flag )printf("%s is a palindrome\n", str);elseprintf("%s is not a palindrome\n", str);}};int main(){char str[40];int n;printf("Enter a number :\t");scanf("%d", &n);check::armstrong(n);//no object is need as it a static functionprintf("Enter a string :\t");scanf("%s", str);check::palindrome(str);return 0;}
#include<stdio.h> #include<conio.h> #include<string.h> int main() { int tmp,i; char str[30]; printf("Enter any string: "); gets(str); for(i=0; str[i]!='\0'; i++) { if(str[i-1]==' ' i==0) { if(str[i]>='a' && str[i]<='z') str[i]=str[i]-32; else if(str[i]>='A' && str[i]<='Z') str[i]=str[i]+32; } printf("%c",str[i]); } getch(); return 0;}
RemoveSpaces (char *str) { char *new = str; while (*str != '\0') { if (*str != ' ') *(new++) = *str; str++; } *new = '\0'; }
As of Java 1.6 it has 3: StringTokenizer(String str) StringTokenizer(String str, String delim) StringTokenizer(String str, String delim, boolean returnDelims)
void to_uppercase (char* str) { if (str == 0) return; while (*str != '\0') { if (*str>='a' && *str<='z') *str-=32; ++str; } }
Here's a simple C program to display vowels from a given string: #include <stdio.h> int main() { char str[100]; printf("Enter a string: "); fgets(str, sizeof(str), stdin); printf("Vowels in the string: "); for (int i = 0; str[i] != '\0'; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U') { printf("%c ", str[i]); } } return 0; } This program prompts the user for a string, then iterates over each character to check if it's a vowel, and displays the vowels found.
The Sony STR DH700 AV receiver has the power of 7.1 channels.
#include<stdio.h> int main() { char str[100]; int i; printf("Please enter a string: "); // gets(str); // fgets is a better option over gets to read multiword string . fgets(str, 100, stdin); // Following can be added for extra precaution for '\n' character // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL; for(i=0;str[i]!=NULL;i++) { if(str[i]>='A'&&str[i]<='Z') str[i]+=32; else if(str[i]>='a'&&str[i]<='z') str[i]-=32; } printf("String in toggle case is: %s",str); return 0; }
2 str/ range
str
Well to make a perfect str pure you would simply train your str