Write a C program to read string "Hello Gujarat" from the user and display it in the following
different format
(a) Hello
(b) Gujarat
(c) Hello Gujarat
(d) Hello G
Answers
Answer:
Here's a PSEUDO C O D E for achieving this. If you can understand it, you can do it in any PL.
Explanation:
Basically, C stores string as a character array, so all you gotta do is iterate through the particular indexes in the array and print out the respective characters in the index, something just like this.
char array[length_of_string]
array=get_input_from_user()
for(int i=starting_index;i<upto_length;i++){
print(array[i])
}
Remember the program above is not a valid C program, it is just the algorithm of how you're supposed to do it.
So for "Hello", starting_index will be 0 and upto_length will be 5
Explanation:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char a[20]="Hello";
char a[20]="Gujarat";
char a[ ]="G";
printf("(a) %s",a);
printf("\n(b) %s",b);
printf("\n(c) %s %s",a,b);
printf("\n(d) %s %s",a,c);
getch();
}