Sona Programming Club

Sona Programming Club SProC ( Sona Programming Club ) has been started in order to improve the programming skills of the students studying in Sona College of Technology.

Activities:
1. Train students to solve programming problems of varying difficulty levels given in websites like www.codechef.com, www.spoj.pl, etc.
2. Meet weekly once and discuss about various algorithms.
3. Periodically suggest books to learn various programming languages.
4. Frequently conduct innovative events related to programming and motivate students to develop programming skills.
5. Regularly update the new standards and changes of the programming languages.

07/03/2014

A C program without semicolon
C program to display “India” without using ';' in the whole program:

For writing this program, we should first understand what printf returns and its prototype. The function declaration of printf is
int printf ( const char *, ... ) ;
It takes variable number of arguments, displays the string till a NULL character is found and returns the number of characters
printed.

Now, the program:
# include
void main()
{
if ( printf ( “India” ) )
{
}
}

The printf () returns 5 in this case. Hence, the 'if' condition is true, but, we are not doing anything even if the condition is true.

02/03/2014

A C program without main:
As soon as you see the title, you might be wondered whether this is possible. But, it's actually possible.

# include

# define modify(t, r, a, i, n, s) i # # t # # a # # r
# define change modify(a, n, i, m, a, l)

int change()
{
printf("C without main!\n");
return 0;
}

If you still don't trust this program, compile and execute it. Shocked ? In fact, there is a main in this program, but hidden. This is based on the concept of token pasting. What happens here is, change is initially replaced by modify(a, n, i, m, a, l). The arguments are then replaced as follows
t = a
r = n
a = i
i = m
n = a
s = l

The statement i # # t # # a # # r gets changed to m # # a # # i # # n, which is then concatenated as main. Eventually, 'change' is changed to 'main'.

23/12/2012

Dear friends,
SProC is back again to ignite your programming skills !
Come, Code, Compete.!!
www.sproc.tk

Sona Programming Club

09/08/2012

Live demonstration of Aspirations2020 contest will be done on 10/08/2012 at lecture hall 502.

25/04/2012

Date of post: 19.4.12
Category: Questions
Number: 12
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"

Answers for the questions asked on 12.4.12:
1. Question:
main() { int a = '1', b = '11' ; printf ( "%d %d", a, b ) ; }
Answer: 49 12593
Explanation: The value is stored as binary in consequent memory.
'1' is stored as 0011 0001 whose integer equivalent is 49. Similarly, '11' is stored as 0011 0001 0011 0001 whose integer value is 12593.

2. Question:
main() { int y = 7 ; if ( !!y ) printf ( "%d", !y ) ; else printf ( "%d", y ) ; }
Answer: 0
Explanation: !y makes non-zero ( 7 ) value as 0 and !!y makes zero value as 1 ( True )

3. Question:
main () { int i = 1 ; j = -1 ; if ( printf ( "%d", i ) > printf ( "%d", j ) ) printf ( "%d", i ) ; else printf ( "%d", j ) ; }
Answer: 1-1-1
Explanation: printf returns the number of characters displayed

4. Question:
main() { int i = -1 ; if ( i ++ ) printf ( "True" ) ; else printf ( "False" ) ; }
Answer: True
Explanation:
i ++ is post increment and -1 is also true

5. Question:
main() { int a = 12 ; printf ( "%p", a ) ; }
Answers: 0xc for gcc compiler ; 000C for Turbo C compiler
Explanation: The hexadecimal equivalent is printed for %p.

18/04/2012

Date of post: 12.4.12
Category: Questions
Number: 11
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"

Answers for questions asked on 5th April, 2012:
1.
Question:
Predict the output
main() { char str[] = "Sona\0Programming\0Club" ; printf ( "%s %s %s\n", str + 17, str + 5, str ) ; }

Answer:
Club Programming Sona
Explanation:
The values 17 and 5 are added to the base address of the string 'str' and the behaviour of printf is it prints till a null character is encountered. Though only "Sona" is stored in str, "Programming" and "Club" are stored in subsequent memory locations.

2.
Question:
What is the output?
main() { int i = 0 ; ! i && printf ( "Text" ) ; }

Answer:
Text

Explanation:
The '!' operator converts 0 to 1, which is true and the printf is evaluated as the behaviour of '&&' is to check the second instruction only if the first one is true.

3.
Question:
What would be the output?
main () { printf ( "What\0are you doing ? " ) ; }

Answer:
What

Explanation:
The behaviour of printf is to print characters only till it reaches a \0 ( null ) character.

4.
Question:
Predict the output
main() { printf ( "Information" ) || printf ( "Technology" ) ; }

Answer:
Information

Explanation:
Since the first printf returns 11 ( number of characters printed ), the first expression evaluates to true and since the '||' operator is used, it does not check the second expression ( second printf ).

5.
Question:
Find the output
main() { printf ( "%d", printf ( "2+" ) + printf ( "2=" ) ) ; }

Answer:
2+2=4

Explanation:
Because of the ex*****on order of the printf statements.

Questions to be answered on or before 18th April, 2012:
Predict the output [2 marks] *
main() { int m = 21000 ; float n = 1.2e100 ; printf ( "%d %d", m, n ) ; }
13392 0
21000 0
13392 1.2e100
21000 1.2e100

What is the output? [2 marks] *
main() { int j ; for ( j = 0 ; j ++

11/04/2012

Date of post: 5.4.12
Category: Questions
Number: 10
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"

Answers for last weeks questions:
1.Answer: All three [ In-fact the option should have been All the above ]

2. Answer: interrupt

3. Answer: char

4. Answer: Equal
Explanation: The comparison is made bitwise. ( So, both will be equal ).

5. Answer: Function

Questions to be answered on or before 11.4.12:
1. Predict the output [2 marks]
main() { char str[] = "Sona\0Programming\0Club" ; printf ( "%s %s %s\n", str + 17, str + 5, str ) ; }

Sona Programming Club
Club Programming Sona
Syntax error
Garbage values

2. What is the output? [2 marks]
main() { int i = 0 ; ! i && printf ( "Text" ) ; }

Text
No output
Syntax error
None of the above

3. What would be the output? [2 marks]
main () { printf ( "What\0are you doing ? " ) ; }

What are you doing ?
What
No output
Error

4. Predict the output [1 mark]
main() { printf ( "Information" ) || printf ( "Technology" ) ; }

Information
Technology
TechnologyInformation
InformationTechnology

5. Find the output [1 mark]
main() { printf ( "%d", printf ( "2+" ) + printf ( "2=" ) ) ; }

2+2=4
42+2=
2=2+4
Error

Website: www.sonasproc.tk

04/04/2012

Date of post: 30.3.12
Category: Questions
Number: 9
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"

Answers for last week:
1. Answer: If you have used gcc compiler, the answer would be 4 5 5. If Turbo C complier, is used, the answer will be 2 5 5.
Explanation: The sizeof some data types will vary from compiler to compiler. Each character takes 1 byte in both the compilers. So, the size if 5 including the NULL.
( Both are evaluated as right answers ).
-------------------------------------------------------------------------------------
2. Answer: 1==1 is TRUE.
Explanation: The conditional operator is used.
-------------------------------------------------------------------------------------3. Answer: 6
Explanation: The '\n' is taken as a single character and NULL is not counted
-------------------------------------------------------------------------------------4. Answer: No output
Explanation: Both strings are equal and hence 0 is returned by strcmp. 0 is false condition and hence the statement printf is not executed.
-------------------------------------------------------------------------------------5. Answer: 5 4
Explanation: sizeof returns ( number of bytes occupied ) value including NULL and strlen returns ( number of characters ) value excluding NULL.
-------------------------------------------------------------------------------------
Questions to be answered on or before 4.4.12:
1. Which of the following declaration(s) is(are) correct ? [2 marks] (i) enum cricket {Gambhir,Smith,Sehwag}c;
(ii) enum cricket {Gambhir,Smith,Sehwag};
(iii) enum {Gambhir,Smith=-5,Sehwag}c;
(iv) enum c {Gambhir,Smith,Sehwag};

(i)
(i) (ii)
(i) (iii)
(i) (ii) (iii)
All three


2. Which of the following does not modify data type in C? [2 marks]

extern
interrupt
huge
register
All the above


3. Which of the following is integral data type in C? [2 marks]

float
void
char
none


4. Predict the output [1 mark]
main(){ int a=-5; unsigned int b=-5u; if(a==b) printf("Equal"); else printf("Empty"); }

Equal
Empty
Error


5. Which of the following is not derived data type? [1 mark]

Function
Pointer
Enumeration

Website: www.sonasproc.tk
Happy programming !

This site is to improve the programming skills of the students of Sona College of Technology.

26/02/2012

Maximum and minimum:
Problem:
Write a C program to find the largest and smallest value in the given numbers.

Input:
First line contains the number of inputs, n.
After that 'n' lines follow each representing a number.

Output:
Largest and smallest values in the given set of numbers separated by a space.

Constrains:
1 < n < 20000
Each value ranges between 0 and 10000 inclusive.

Sample input:
5
3
5
0
4
1

Sample output:
5 0

Note:
Time and space complexities will not be considered, however, the best ( most efficient ) program will get the best prize.

Deadline to solve:
March 31, 2012

Contact:
For any doubts or queries, just comment.

26/02/2012

Date of post: 16.02.2012
Category: Questions ( 3rd year )
Question paper number: 1a
Post content:

SONA PROGRAMMING CLUB-QUESTIONS FOR 3RD YR:

1. Look at the sample program and predict the output

void main()

{

int const * p=5;

printf("%d",++(*p));

}

Answer:

Compiler error: Cannot modify a constant value.

Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".



2. Look at the sample program and predict the output

main()

{

char s[ ]="man";

int i;

for(i=0;s[ i ];i++)

printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}

Answer:

mmmm

aaaa

nnnn







Explanation:

s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

3. Look at the sample program and predict the output

main()

{

float me = 1.1;

double you = 1.1;

if(me==you)

printf("I love U");

else

printf("I hate U");

}

Answer:

I hate U

Explanation:

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.



4. Look at the sample program and predict the output

main()

{

int c[ ]={2.8,3.4,4,6.7,5};

int j,*p=c,*q=c;

for(j=0;j

16/02/2012

Date of post: 16.02.2012
Category: Questions
Question number: 3
Post content:
Sona College of Technology
Programming Club ( SProC )
“Let us C beyond the C”
Answers for questions asked on 15.2.12:
1. b) 5 6
2. a) float should be changed to int
b) a[2] should be changed to a[3]
c) “,%d” should be added in printf
3. Only s[strlen(s)] should be changed to s[strlen(s) – 1]
s[0] is internally interpreted as *(s + 0) [which means take the value at the location after moving 0 positions from the base address s]. By the commutative property of addition, s + 0 = 0 + s. Therefore *(s+0) = *(0+s) which is also equal to 0[s].
Hence, s[0] = *(s+0) = *(0+s) = 0[s].
4. Garbage value
5. b) ,H ( Null character is stored at the 8th position )

Questions for 16.2.12 ( input and output statements ):
1 Output of the program will be: (1)
main() { int a = 40 ; printf("%d %d", a ); }
a. 40, 40 b. 40, (garbage) c. (garbage), 40 d.
______________________________________________________________
2 What is the Output of the code: (1)
main() { int i; printf("%d", &i)+1; }
a. address of i b. address of i + 1. c. Compile error d. None of the above
______________________________________________________________
3 Output of the code will be: (2)
main() { int i = 100, j = 50 ; printf("%d", i, j ); }
a. 100 b. 50 c. 100 50 d.
______________________________________________________________
4 Output of the program will be: (1)
main() { int i=0, j=0; scanf("%d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j); }
a. Runtime error b. 0, 0 c. Compile error d. Input values
______________________________________________________________
5 How will you print % character? (2)
a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)
______________________________________________________________

Note:
1. Some of these questions may be useful for your internal exams
2. Those who answer todays questions will be getting bonus credits.
3. Send your feedback and suggestions to [email protected]

Tips:
1. Always try to write programs with indentation.
2. Try to compile programs with gcc compiler which is the current standard.
3. Have meaningful variable names so that anyone can understand the purpose of the variable by just looking at its name. Eg: instead of a, b or s, use val1, val2 or sum.
Happy programming !

16/02/2012

Date of post: 15.02.2012
Category: Question
Question number: 2
Post content:
Sona College of Technology
Programming Club ( SProC )
“Let us C beyond the C”
Answers for questions asked on 14.02.2012:
1. a) 23
2. main() { int a = 10 ; printf ( “%d”, a ) ; }
3. c) do.. while
4. Not equal ( since variable a is declared as int and 2.5 is assigned, implicit type conversion takes place and hence 2 is stored in a )
5. True ( due to implicit type conversions )

Questions for 15.02.2012 ( based on array ):

1. Predict the output: ( 1 )
main() { int a[]={1, 5, 12} ; printf("%d %d",a[0+1],a[1]+1 ); }
a) 2 6 b) 5 6 c) 5 12 d) error
----------------------------------------------------------------------------------------------------------

2. Debug the code: ( Write the correct code – Output should be 5,3,2 ) ( 1 )
main() { float a[2] = { 5, 3, 2 } ; printf ( “%d,%d”,a[0],a[1],a[2] ) ; }
---------------------------------------------------------------------------------------------------------

3. Debug the code: ( Output : SPC ) ( 2 )
main() { char s[] = “SProC” ; printf ( “%c%c%c”, 0[s], s[1], s[strlen(s)] ) ; }
----------------------------------------------------------------------------------------------------------

4. Predict the output: ( 1 )
main() { int a[5] ; printf ( “%d”, a[3] ) ; }
----------------------------------------------------------------------------------------------------------

5. Predict the output: ( 2 )
main() { char a[8] = “Welcome” ; printf ( “%c,H”, a[8] ) ; }
a) Garbage,H b) ,H c) Error d) e,H
----------------------------------------------------------------------------------------------------------

Topmost Coders :
1. D. Jeevaraj – ECE
2. A. Hariharan – ECE
3. M. Anbarasu – ECE
4. P. Vasanth Kumar – Civil
5. M. Tamil Selvam – Civil
6. R. Sthanu Subramanian – Civil

Note:
(1). All the above students hold the first rank.
(2). Contact [email protected] for any queries and for feedback

Happy programming !

Address

Salem
636005

Website

Alerts

Be the first to know and let us send you an email when Sona Programming Club posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Business

Send a message to Sona Programming Club:

Share