"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 17 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 ?    9 Yes 5 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 / 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 ?    6 Yes 4 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 ?    2 Yes 1 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 / 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 ?    10 Yes 19 No

Post New Answer

More C Interview Questions

What is the use of the function in c?

0 Answers  


Under what circumstances does a name clash occur?

0 Answers   InterGraph,


Explain what is the difference between a free-standing and a hosted environment?

0 Answers  


What is a stream water?

0 Answers  


What is difference between %d and %i in c?

0 Answers  


main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); }

11 Answers   CISOC, CitiGroup, College School Exams Tests,


Explain how can I prevent another program from modifying part of a file that I am modifying?

0 Answers  


what is ram?

3 Answers   TCS,


i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } printf("%d", k);

8 Answers   HCL,


where do we use volatile keyword?

1 Answers  


WHAT IS LOW LEVEL LANGUAGE?

2 Answers  


write a programming in c to find the sum of all elements in an array through function.

0 Answers  


Categories