#include
#include
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;
int main()
{
string myStr = "";
cout << endl << "Enter your line (to finish press #): ";
getline(cin, myStr, '#');
cout << endl << "You have entered: "" << myStr << """
<< endl;
system("PAUSE");
return 0;
}
//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }
print c co com comp compu
Write a c program that reads your first name and surname when you enter them. Each part of your name should not be more than 12 characters. Finally, have the program display your full name.
import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }
#include <iostream> #include <string> using std::cin; using std::cout; using std::endl; using std::string; int main() { cout << "Enter name of your favorite TV show: \n"; string tvShow = ""; cin >> tvShow; for (int i = 0; i < 15; i++) { cout << endl << tvShow; } cout << endl << endl; system("PAUSE"); return 0; }
//C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings #include<stdio.h> #include <string.h> int main() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; }
print c co com comp compu
#include<stdio.h> #include<conio.h> void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i<=19) { scanf("%c",&string[i]); i++; } while(i>=0) { printf("%c",string[i]); i--; } getch(); } In this program it is compulsory to enter 20 characters. Now we can write a program in which it is not necessary. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length>0) { printf("%c",string[length]); length--; } getch(); }
Here's a Python program that accomplishes this: def convert_case(input_str): return input_str.swapcase() user_input = input("Enter a string: ") converted_str = convert_case(user_input) print("Converted string:", converted_str)
Write a c program that reads your first name and surname when you enter them. Each part of your name should not be more than 12 characters. Finally, have the program display your full name.
import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }
#include <iostream> #include <string> using std::cin; using std::cout; using std::endl; using std::string; int main() { cout << "Enter name of your favorite TV show: \n"; string tvShow = ""; cin >> tvShow; for (int i = 0; i < 15; i++) { cout << endl << tvShow; } cout << endl << endl; system("PAUSE"); return 0; }
#include <iostream> #include <string> int main() { std::string myStr = ""; std::cout << std::endl << "Enter a string: "; std::cin >> myStr; system("PAUSE"); return 0; }
public static void main(String[] args) { int val = 100; int val1 = 50; System.out.println("Number of digits in " + val + " is: " + new String(val + "").length()); System.out.println("Number of digits in " + val1 + " is: " + new String(val1 + "").length()); }
I assume the program should be case-sensitive. Here is a code of such program:#include #include int main() {char str1[100];char str2[100];printf("Please enter first string: ");gets(str1);printf("Please enter second string: ");gets(str2);if (strcmp(str1, str2) == 0) {printf("Strings are Equal.\n");} else {printf("Strings are Not Equal.\n");}return 0;}Testing:Please enter first string: APlease enter second string: AStrings are Equal.Please enter first string: aPlease enter second string: AStrings are Not Equal.If you want to make not case-sensitive comparing before checking you should make both string in lowercase or uppercase.Here is how it should look:#include #include #include void upString(char *str);int main() {char str1[100];char str2[100];printf("Please enter first string: ");gets(str1);printf("Please enter second string: ");gets(str2);upString(str1);upString(str2);if (strcmp(str1, str2) == 0) {printf("Strings are Equal.\n");} else {printf("Strings are Not Equal.\n");}return 0;}void upString(char *str) {register int ind = 0;while (str[ind]) {str[ind] = toupper(str[ind]);ind++;}}Testing:Please enter first string: aaaPlease enter second string: AAAStrings are Equal.Please enter first string: aaaPlease enter second string: aAaStrings are Equal.Note: You should not be using gets() function in real-world application. There is no way you can limit number of characters to read thus allowing to overflow buffer. It was used only for example.
program SumAndDifference; var num1, num2, sum, difference: integer; begin write('Enter first number: '); read(num1); write('Enter second number: '); read(num2); sum := num1 + num2; difference := num1 - num2; if sum > difference then written('The sum is greater: ', sum) else written('The difference is greater: ', difference); end. This program will prompt the user to enter two numbers, calculate their sum and difference, and then compare the two values. If the sum is greater than the difference, it will display the sum; otherwise, it will display the difference.
You need to scan through the string and keep track of the vowelsoccurring. Here is a sample program:#include#includeint countVowels(char[] s){int count = 0, i;for( i=0; char[i] != '\0'; i++){switch(char[i]){case 'a':case 'e':case 'i':case 'u':case 'o': count++;break;}}return count;}int main(){char str[256];printf("Enter the string:\t");scanf("%s", str);printf("The number of vowels in the string are :%d\n", countVowels(str));return 0;}