- 0
Notifications Mark All Read
- Login
- Get Prime
Coding Question 1 Free Section
Program to Capitalise a String
C
#include <stdio.h> void upper_string(char []); int main() { char string[100]; printf("Enter a string to convert it into upper case\n"); gets(string); upper_string(string); printf("The string in upper case: %s\n", string); return 0; } void upper_string(char s[]) { int c = 0; while (s[c] != '\0') { if (s[c] >= 'a' && s[c] <= 'z') { s[c] = s[c] - 32; } c++; } }
using strUPR Method
#include <stdio.h> #include <string.h> int main() { char string[1000]; printf("Input a string to convert to upper case\n"); gets(string); printf("The string in upper case: %s\n", strupr(string)); return 0; }
Java
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to PrepInsta.com"); System.out.print("Return Value :" ); System.out.println(Str.toUpperCase() ); } }
Good
import java.util.Scanner;
public class StringCaptalise {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.println(str.toUpperCase() );
}
num=”prepinsta”
num1=num.upper()
print(num1)
The first code will never work.I belief the c is the index value which you haven’t used.