whats output this program  in c++:   for(i=0;1;i++) printf("god")   and  what?
339889
You will get a error because you need a loop condition it cant be just 1. for example to print god 5 times make loop condition like for(i=0; i <=5;i++) then it will print "god" five times.
814965
what c++ program are you referring to ...anyway the syntax is\n\n#include<iostream.h>\n#include<conio.h>\n...include all the header files here ..\n\nint count()\n  {\n     function body\n     return value #integer value to be returned \n\n  }\n\nother functions\n\nvoid main() \n\n   {\n\n# this is the main function \n\nint a,b,c;\nfloat al,bl;\nstring str;\n\n#declare the variables\n\n#get the inputs from the user\ncout<<"enter the value of a ";\ncin>>a;\n...\n...\n\ncall the functions\n\nb=count()\n..\n#do what ever processing has to be done\n } # program closing curly braces\n\n\nhope this helps\n\nthis is a excellent c++ tutorial \n\nhttp://www.geocities.com/sstutor\n\ncprogramming.com is also pretty good
334651
If you use an array, then use the mod operator to choose the first element of the array to access the array once you have passed the last element of the array. \n\ni = 0; \nwhile (1)\n{\n   printf ("%d", a[i%n]); // 'n' is the size of the array\n   i++;\n}
935645
main() { static char *a="n0body"; char b[512],*c,*d;\n  while (c=gets(a)) for (d=a;c;*c^=*d,c++,d=*++d?d:a);\n  printf ("%s&#92;n",b);}\n\n\nhappy?
288451
in c:\nchar name[20];\nfor(i=0;i<=20;i++)\n  {\n   scanf("%c",&name[i];\n   }\nfor(;i>=20;i--)\n {\n  printf("%c");\n};\ni think this will wrk;\nthe logic is jst accept the name into a char array and start reading back.
1024904
Thats a recursive program for you.\nAnd I put an arbitrary limit of 9 there. You can change that for yourself.\n\n#include <stdio.h>\n\nvoid triangle(char ch, int count) {\n        int temp=0;\n        if (count==1) {\n                printf("%c&#92;n", ch);\n                return;\n        }\n        triangle(ch, count-1);\n        for(;temp<count;temp++) {\n                printf("%c", ch);\n        }\n        printf("&#92;n");\n}\n\nint main() {\n        char ch='*';\n        int count=0;\n        while((count<=0)||(count>=10)) {\n                printf("Enter the size of triangle (less than 10)&#92;n");\n                scanf("%d", &count);\n        }\n        triangle(ch, count);\n}
256646
I'll put a bit of more information than the previous two answers.. or it'll seem like I'm answering for 2 points ;-)\n\nA for loop in C++ basically has the syntax:\n\nfor([initializations];[condition check];[updates])\n{\n  //statement1;\n  //statement2;\n}\n\nInitializations: Initialize counters, iterators.. any data to be set or reset before the loop starts executing. Multiple initialization statements can be provided in a comma-separated-list.\n\nCondition Check: While the condition is true, keep iterating through the loop. Dont make this a list.\n\nUpdates: Update iterators, indices, counters etc. which need to be updated with every iteration of the loop. Again this can be a comma-separated-list.
397803
/*\n\ni need to know an example of writting a program in c\nlanguage under linux using threads?\n\nwrite aprogram to calculate the result of the equation\nY=3sin(x)+6cos(x)+5x2 so each term accomplished by a\nthread. The main thread will calculate the result.\n\n*/\n\n\n#include <pthread.h>\n#include <math.h>\n#include <stdlib.h>\n#include <stdio.h>\n\n/* static global location -- all threads will read */\nstatic double x;\n\nstatic void*\nthree_sinx(void*p)\n{\n  double* result = (double*)p;\n  *result = 3 * sin(x);\n  return 0;\n}\n\nstatic void*\nsix_cosx(void*p)\n{\n  double* result = (double*)p;\n  *result = 6 * cos(x);\n  return 0;\n}\n\nstatic void*\nfive_x_squared(void*p)\n{\n  double* result = (double*)p;\n  *result = 5 * x * x;\n  return 0;\n}\n\n/*\n *\n * Y = 3sin(x) + 6cos(x) + 5x2\n *\n */\n\nint\nmain(int argc, char* argv[])\n{\n  double result[3]; /* one location for each thread */\n  pthread_t tid[3];\n  void *r;\n  int i;\n\n  /* Set "x" to double value passed in on command line */\n  x = argc>1 ? strtod(argv[1], 0) : 0;\n\n\n  /*\n   *  Since result areas are distinct, no mutex needed\n   */\n  if (pthread_create(&tid[0], NULL,\n    three_sinx, &result[0]) != 0) {\n    perror("pthread_create[0]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[1], NULL,\n    six_cosx, &result[1]) != 0) {\n    perror("pthread_create[1]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[2], NULL,\n    five_x_squared, &result[2]) != 0) {\n    perror("pthread_create[2]"), exit(-1);\n  }\n\n  /* Synchronize on the completing child threads */\n  for (i=0; i<3; i++) {\n    if (pthread_join(tid[i], &r) != 0) {\n      perror("pthread_join");\n      exit(-1);\n    }\n  }\n\n  /* main thread will now combine the result */\n  printf("For y=3sin(x)+6cos(x)+5x2, when x=%f, y=%f&#92;n",\n      x, result[0]+result[1]+result[2]);\n\n  return 0;\n}\n\n\n\nTo show that it works:\n\n$ cc pthr.c -lpthread -lm\n\n$ a.out 3.14159\nFor y=3sin(x)+6cos(x)+5x2, when x=3.141590, y=43.347947\n\n$ a.out 0\nFor y=3sin(x)+6cos(x)+5x2, when x=0.000000, y=6.000000
943372
u have to ponit it or use\n\nthese are the 2 way's:\n\n#include <iostream>\nusing namespcae std;\nint main()\n{\nint num[8];\nint index;\n\nnum[0] = 42;\nnum[1] = 2001;\nnum[2] = 7;\nnum[3] = 180;\nnum[4] = 99;\nnum[5] = 1993;\n\nfor(index = 0; index <= 5; index++)\n{\nstd::cout<< index[num] << endl;\n}\n system("pause");\nreturn 0;\n}\n\nor\n\n#include <iostream>\n#define MAX 20\nusing namespcae std;\n\nint main()\n{\n\nint a[MAX] = {23,43,4,5,34,343,12,14};\nint b;\n\ncout.setf(ios::right);\n\nfor(b = 0; b < MAX; b++){\n\ncout << endl << endl;\n\ncout << "The Elemnt in ";\n\ncout.width(2);\n\ncout << (b +1) << " is ";\n\ncout.width(2);\n\nstd::cout << b[a];\n}\nreturn 0;\n}
971319
#include <iostream>\n#include <iomanip>\n\nusing namespace std;\n\nint main() {\n\n  cout << "Welcome to F&#92;'Zone&#92;n"\n      << "&#92;n"\n      << "Please select from the following menu.&#92;n"\n      << "&#92;n"\n      << "1: Quarter pounder combo&#92;n"\n      << "&#92;n"\n      << "2: Bacon burger&#92;n" \n      << "&#92;n"\n      << "3: Swiss mushroom burger&#92;n"\n      << "&#92;n"\n      << "To place your order, enter the number of the meal you would like.&#92;n"\n      << "For instance enter 2 for a Bacon Burger.&#92;n"\n      << "&#92;n"\n      << "Please enter your selection now: ";\n  char x;\n  x = getchar();\n  double total = 0.0;\n  switch (x) {\n    case '1' :\n      total = 4.59;\n      cout << "Would you like a &#92;'biggy&#92;' size? It costs $0.39 extra.&#92;n"\n          << "Type in a 'Y' or a 'N': ";\n      //x = getchar();\n      cin >> x;\n      if (x == 'Y') {\n        total += 0.39;\n        cout << "You have chosen to have a &#92;'biggy&#92;' size.&#92;n";\n      }\n      cout << "Would you like cheese with that? It costs $0.25 extra.&#92;n"\n          << "Type in a 'Y' or a 'N': ";\n      //x = getchar();\n      cin >> x;\n      if (x == 'Y') {\n        total += 0.25;\n        cout << "You have chosen to have cheese.&#92;n";\n      }\n      break;\n    case '2' :\n      // similar to 1, just change the price and messages.\n      break;\n    case '3' :\n      // similar to 1, just change the price and messages.\n      break;\n    default :\n      cout << "You have not ordered a menu item.";\n      return 1;\n  }\n  cout << "The total of your order is $" << setiosflags(ios::fixed)\n      << setprecision(2) << total << resetiosflags(ios::fixed);\n}
444754
This sounds like school work, its a fairly simple program. you will probably want to use the cout and cin function which needs you to include iostream.h \n\nsimply use cout to print to screen, ask for input etc. then take the input using cin and store it to a int variable.\n\na good way to do it would be to ask the user what they wish to do, eg subtract, divide and take that operator first, a symbol or a number to show choice. then the next line asks for the numbers to be input.\n\neg:\n\n---------\n\nHello. what do you wish to do:\n1 - subtract\n2 - divide\n3 - etc etc\n\n>\n\n-------------\n\nthen use an if function or maybe a switch to check what their input was and do the artithmatic.\n\nso a very basic prgram may look like this:\nit may have errors i havant checked it.\n\n-----------------\n\n#include <iostream>\n\nint main() \n{\nint number;\n\n    cout << "Hello, input a number" << endl;\n    cin >>number;\n    return 0;\n}\n\n------\n\nEDIT; i re read the req, you might find inputting the selection to a char better, then check the char to see what symbol is stored in it, eg + / -. and maybe use a char array for the number input. simple take the char array, check for the space. split the numbers into 2 and caste then to an int. sounds complicated but it isnt to hard.\n\nsorry about spelling mistakes.
998792
What is (char*) doing there? Simple! It converts int to char for ii and float to char for aa. The compiler doesn't automatically convert int to char or float! (because int is larger then char, and by converting it you loose data, same for float..).\nAnd now refering to the output... It depends on what system this source is compiled, and nevertheless on the compiler you are using! The problem consists in converting an int to a char, and it depends on the compiler how many bytes are allocated when declaring an int! (same for converting float to char)
409704
I may not have written many programs in Java, but that sure as hell doesn't look like Java to me.\n\nEdit: It's actually C as you can see from the includes:\n#include<stdio.h>\n#include<conio.h>\n#include<math.h>\n#include<stdlib.h>\n\nC++ doesn't use <something.h> it just uses plain <something>.
906761
Try this:\n\nvoid addIt(int* begin, int* end, int x)\n{\nint* p;\nfor (p=begin; p!=end; ++p) {\n*p = *p + x;\n}
408935
Hey,\nthe code in JAVA would look like this ::\n\nclass test {\npublic static void main(String a[]) {\nfor(int i=1;i<100;i++) {\nSystem.out.print("&#92;t"+i+"&#92;n");\n}\n}\n}
94728
well, you didn't specify a language so here's korn shell:\n\n#! /bin/ksh\nread c\nTEMP=1\nwhile [ $TEMP -lt $c ]; do\n  echo "**********************************" | cut -c1-$TEMP\n  let "c += 1"\ndone\n\nmy c++ is a bit rusty, but the loop would look like this:\n\nwhile ( c = 1; c <= count ; c++ )\n{\n  while ( d = 1; d <= c; d++ )\n  {\n    cout << "*";\n  }\n  cout << endl;\n}\n\nhope this helps :-)
604143
here is a program for 10 numbers in ascending order\n\n#include <iostream.h>\n#include <conio.h>\n\nvoid main()\n{\nclrscr();\nint array[10],t;\nfor(int x=0;x<10;x++)\n{\ncout << "Enter Integer No. " << x+1 << " : " << endl;\ncin>>array[x];\n}\nfor (x=0;x<10;x++)\n{\nfor(int y=0;y<9;y++)\n{\nif(array[y]>array[y+1])\n{\nt=array[y];\narray[y]=array[y+1];\narray[y+1]=t;\n}\n}\n}\ncout << "Array in ascending order is : ";\nfor (x=0;x<10;x++)\ncout << endl << array[x];\ngetch();\n}\n\nThis program takes in the ten integers array[x] to be stored in the single-dimensional array as a screen input from the user.\nIt then sorts out these ten integers into ascending order and prints them out using the 'cout' command.