"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

What is the function of ceil(X) defined in math.h do? A)It returns the value rounded down to the next lower integer B)it returns the value rounded up to the next higher integer C)the Next Higher Value D)the next lower value

3 Answers   Accenture, Wipro,


what are the stages of compilation

1 Answers   Bosch,


How can I insert or delete a line (or record) in the middle of a file?

0 Answers  


write a c/c++ programthat connects to a MYSQL server and checks if the INNoDB plug in is installed on it.If so your program should print the total number of disk writes by MYSQL.

0 Answers   BirlaSoft,


Explain the concept and use of type void.

0 Answers  






What is a Genralised LInked List?? Please give a detailed explation of it..

1 Answers  


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


What are the application of void data type in c?

0 Answers  


What is the auto keyword good for?

0 Answers  


what will the following program do? void main() { int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1

1 Answers   IBM,


Define a structure to store roll no, name and marks of a student. Using the structure of above write a ‘C’ program to create a file “student.dat”. There must be one record for every student in the file. Accept the data from the user.

0 Answers  


How can I set an array's size at run time?

9 Answers  


Categories