"I LOVE MY COUNTRY"
write a c program to get "COUNTRY MY LOVE I" as the output.

Use any other programming language. It is not mandatory to
use C.

Answers were Sorted based on User's Feedback



"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / sandeep

#include <stdio.h>

void rev(char *l, char *r);


int main(int argc, char *argv[])
{
char buf[] = "I LOVE MY COUNTRY";
char *end, *x, *y;

// Reverse the whole sentence first..
for(end=buf; *end; end++);
rev(buf,end-1);


// Now swap each word within sentence...
x = buf-1;
y = buf;

while(x++ < end)
{
if(*x == '\0' || *x == ' ')
{
rev(y,x-1);
y = x+1;
}
}

// Now print the final string....
printf("%s\n",buf);

return(0);
}


// Function to reverse a string in place...
void rev(char *l,char *r)
{
char t;
while(l < r)
{
t = *l;
*l++ = *r;
*r-- = t;
}
}

Is This Answer Correct ?    35 Yes 16 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / shaik

#include<stdio.h>

void main ()
{
char str1[]="I LOVE MY COUNTRY",str2[20];
int count,i;
clrscr();
i=0;
While (str1[i]!='')
{
count++;
i++;
}
i=0;
while (str1[i]!='')
{
str2[count-1-i]=str1[i];
i++;
}
str2[i]='';
printf ("reversed string is %s",str2);
getch ();
} // guys check for the syntax typed from phone sry

Is This Answer Correct ?    11 Yes 7 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / knk

i think it finets a tower of hanoi prob,its pgm shud work jus

Is This Answer Correct ?    9 Yes 6 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / iravani

#include<iostream>
#include<vector>
using namespace std;
int main()
{
string s,s1;
int n,i,j,k;
vector<string>v,v1;
cin>>n;
getline(cin,s,'\n');
v.push_back(s);
for(i=0;i<n;i++){
getline(cin,s,'\n');
v.push_back(s);
}
for(i=0;i<v.size();i++){
for(j=0;j<v[i].size();j++){
while(v[i][j]!=' ' && j<v[i].size()){
s1+=v[i][j];
j++;
}
v1.push_back(s1);
s1.clear();
}
for(k=v1.size()-1;k>=0;k--){
cout<<v1[k]<<" ";
}
v1.clear();
cout<<endl;
}

u can give input as many string as u want..

Is This Answer Correct ?    8 Yes 5 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / archana

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
char samp[] = "I LOVE MY COUNTRY";
char *ch;
string st;
vector<string> vec;
ch = strtok(samp, " ");
while(ch != NULL) {
printf("%s\n", ch);
vec.push_back(ch);
ch = strtok(NULL, " ");
}
while(!vec.empty()) {
cout << vec.back() << " ";
vec.pop_back();
}
}

Is This Answer Correct ?    5 Yes 4 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / rabi

#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[100];
//string s;
gets(s);
int len=strlen(s);
int no;
for(int i=len-1;i>=0;i--)
{
if(i==0)
{
no=i;
while(s[no]!=' ')
{
cout<<s[no];
no++;
//if(s[i]==' ')
//break;
}
}
if(s[i]==' ')
{
no=i+1;
while(s[no]!=' ')
{
cout<<s[no];
no++;
if(s[no]=='' || s[no]==' ')
break;
}
cout<<" ";

}
}
}

Is This Answer Correct ?    1 Yes 1 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / aniket singh

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
string str= "I love my country india";
string temp;
int st=0,i;

for(i=0;i<=str.size();i++){
if(str[i]==' '||str[i]==''){

temp = str.substr(st,(i-1)-st+1) + ' ' + temp;
st=i+1;
}
}
cout<<temp<<endl;
return 0;
}

Is This Answer Correct ?    1 Yes 1 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / debmalya paul

package Stringmltp;
import java.util.Scanner;

public class country {

static Scanner in=new Scanner(System.in);

void rev()
{
String s=in.nextLine();
System.out.print(s.substring(10,17) +" "+ s.substring(7,9) +" "+ s.substring(2,6) +" "+ s.substring(0,1));

}
public static void main(String []args)
{
country cn=new country();
cn.rev();
}

}

Is This Answer Correct ?    2 Yes 3 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / elle

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define MAX 20 //define size
int main()
{
int len,j=0;
char *p, *line[MAX],*q;
p=(char *)malloc(MAX);
char *l="i love my country";

int i=0;

while(*l!='\0')
{
if(*l==' ')
//whenever a space is encountered, copy the string q into
//the array
{
*p='\0';
line[i]=(char *)malloc(MAX);
strcpy(line[i],q);
strcpy(p,"");
l++;
i++;
j=0;
}
else
{
if(j==0)
{
q=p;
}
*p=*l;
l++;
p++;
j++;
}
}

*p='\0';
line[i]=(char *)malloc(MAX);
strcpy(line[i],q);

printf("printing in reverse\n");
while(i>=0)
{
printf("%s ",line[i]);
i--;
}
}

Is This Answer Correct ?    2 Yes 4 No

"I LOVE MY COUNTRY" write a c program to get "COUNTRY MY LOVE I" as the output...

Answer / alen

using namespace std;

#include <iostream>

int main()
{
cout<<"\"COUNTRY MY LOVE I\"";
return 0;
}

Is This Answer Correct ?    9 Yes 19 No

Post New Answer

More C Interview Questions

C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

0 Answers  


Write a program to know whether the input number is an armstrong number.

0 Answers   Wipro,


Find if a number is power of two or not?

1 Answers  


struct node { int *a; char *b; char array[12]; }; struct node m,*n; assign the value in *a,*b,char array[12]

3 Answers  


What language is windows 1.0 written?

0 Answers  






HOW TO FIND OUT THE RREVERS OF A GIVEN DIGIT NUMBER IF IT IS INPUT THROUGH THE KEYBORD BY USING C LANGUAGE

3 Answers   Wipro,


write an interactive program to generate the divisors of a given integer.

7 Answers   TCS,


Differentiate between the = symbol and == symbol?

0 Answers  


How can you determine the maximum value that a numeric variable can hold?

0 Answers  


What are keywords c?

0 Answers  


what are bit fields in c?

0 Answers  


How many types of errors are there in c language? Explain

0 Answers  


Categories