Anonymous
Let's say you are given a string. You can get many strings (combination) out of the given original string if you rearrange characters of original string.
String is Palindromable if any one combination is palindrome.
 
Example 1:
Original String: NINIT
Combinations: NINIT, NNIIT,IINNT,ININT,IITNN,NITIN,INTIN,INTNI,NTNII,NNTII and so on
Hariyana Grande
#include <stdio.h>
#include <stdlib.h>
#define MONTHS 12
#define YEARS 5
int main()
{
// initialize rainfall data for 2011-2015
float rain[YEARS][MONTHS] =
{
{4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
{8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
{9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
{7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
{7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
};
int year, month;
float subtot, total;
printf("YEAR\t\tRAINFALL (inches)\n");
for (year = 0, total = 0; year < YEARS; year++)
{
for(month = 0, subtot = 0; month < MONTHS; month++)
{
subtot += rain[year][month];
}
printf("%5d \t%15.1f\n", 2010 + year, subtot);
total += subtot;
}
printf("\nThe yearly average is %.1f inches.\n\n",total/YEARS);
printf("MONTHLY AVERAGES:\n\n");
printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n");
for (month = 0; month < MONTHS; month++)
{
for (year = 0, subtot = 0; year < YEARS; year++)
subtot += rain[year][month];
printf("%4.1f ", subtot/YEARS);
}
printf("\n");
return 0;
}
could somebody please explain the program from "for loop" ? just short explaination will suffice. im confused about loop control variable "year, month"
Amu
_new_node:
pushq %rbp
movq %rsp,%rbp
# IMPORANT: THE ALIGNMENT RULE FOR MALLOC AND OTHER C FUNCTIONS IS THAT THE STACK HAS
# TO BE 16-BYTE ALIGNED. SO, AFTER THE PUSH TO %RBP, THE STACK POINTER %RSP, SHOULD
# BE INCREMENTED OR DECREMENTED IN MULTIPLES OF 16.
# So, two 8-byte pushes is fine.
# the string to write into the new node is pointed to by %rdi
# NOTE: sizeof(NODE) is 216.
# Offsets within NODE are: question_or_animal = 0, left = 200, right = 208
# NULL is 0.
# We'll move s to a callee-saved register, %rbx, so we don't have to repeatedly
# push and pop it when we make calls to malloc and strcpy.
# Similarly, we'll put p in %r12, another callee-saved register.
# first save %rbx and %r12 on the stack.
# FILL THIS IN
push %rbx
push %r12
# then move s to %rbx
# FILL THIS IN
movq %rdi, %rbx
// NODE *p = (NODE *) malloc(sizeof(NODE)); // where sizeof(NODE) is 216
# FILL THIS IN
call _malloc
# put the result of malloc into p (%r12)
# FILL THIS IN
movq %rax, %r12
// p->left = NULL;
// p->right = NULL;
# FILL THIS IN
movq $0, 200(%rax)
movq $0, 208(%rax)
// strcpy(p->question_or_animal, s);
# call strcpy, passing the address of p->question_or_animal and the pointer s (which is in %rbx)
# FILL THIS IN
callq _strcpy
movq %rbx, %rax
// return p;
# restore the callee-saved registers %r12, %rbx
#FILL THIS IN
popq %r12
popq %rbx
popq %rbp
retq
.section __TEXT,__text,regular,pure_instructions
.globl _guess_animal
.p2align 4, 0x90
Ammar
Another example:
This is an array of chars too.
char my_str[] = {'a', 'b', 'c', '\0', '1', '2', '3'};
See the null terminator here?
At index 3.
And this call will print "abc"
printf("%s", my_str);
Why 1, 2 and 3 don't get printed?
Because %s stops reading when it finds null terminator.