Q-2
A goto statement in C programming provides an unconditional jump from the 'goto' to a
labeled statement in the same function.
Flow Diagram
Example:-
#include <stdio.h>
int main () {
/* do loop execution */
LOOP:do {
if( a == 15) {
/* skip the iteration */
a = a + 1;
goto LOOP;
}
}while( a < 20 );
return 0;
}
Q-4
Suppose you use ++ operator as postfix like: var++. The original value of var is
returned first then, var is incremented by 1.
return 0;
}
Q-5
Operator precedence determines the grouping of terms in an expression and
decides how an expression is evaluated. Certain operators have higher
precedence than others; for example, the multiplication operator has a
higher precedence than the addition operator.
#include <stdio.h>
main() {
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d; // ( 30 * 15 ) / 5
printf("Value of (a + b) * c / d is : %d\n", e );
e = ((a + b) * c) / d; // (30 * 15 ) / 5
printf("Value of ((a + b) * c) / d is : %d\n" , e );
e = a + (b * c) / d; // 20 + (150/5)
printf("Value of a + (b * c) / d is : %d\n" , e );
return 0;
}
char
%c Character
unsigned char
short
unsigned short
%d Signed Integer
int
long
float
%e or %E Scientific notation of float values
double
%f Floating point float
float
%g or %G Similar as %e or %E
double
%hi Signed Integer(Short) short
%hu Unsigned Integer(Short) unsigned short
short
unsigned short
%i Signed Integer
int
long
%l or %ld or %li Signed Integer long
%lf Floating point double
%Lf Floating point long double
unsigned int
%lu Unsigned integer
unsigned long
%lli, %lld Signed Integer long long
%llu Unsigned Integer unsigned long long
short
unsigned short
%o Octal representation of Integer. int
unsigned int
long
%p Address of pointer to void void * void *
%s String char *
unsigned int
%u Unsigned Integer
unsigned long
short
unsigned short
%x or %X Hexadecimal representation of Unsigned Integer int
unsigned int
long
%n Prints nothing
%% Prints % character
Q-7
#define is a pre processor directive. Things defined by #define are replaced by the pre
processor before compilation begins.
#include <stdio.h>
int main()
{
printf("%s is over %d years old.\n", NAME, AGE);
return 0;
}
Q-8
The if else ladder statement in C programming language is used to test set of conditions in
sequence. An if condition is tested only when all previous if conditions in if-else ladder is
false. If any of the conditional expression evaluates to true, then it will execute the
corresponding code block and exits whole if-else ladder.
#include<stdio.h>
#include<conio.h>
int main(){
int marks;
getch();
return(0);
}
#include <stdio.h>
int main()
{
float principle, time, rate, SI;
return 0;
}
Q-9 (1*1)+(2*2)+...+(n*n)
int main()
{
int i,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
sum+=i*i;
}
printf("Sum: %d",sum);
return 0;
}
#include <stdio.h>
int main()
{
int number, originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
return 0;
}
Q-11
break Statement
The break statement terminates the loop (for, while and do...while loop) immediately
when it is encountered. The break statement is used with decision making statement
such as if...else.
EX:-
#include<stdio.h>
int main()
{
}
continue Statement
The continue statement skips some statements inside the loop. The continue
statement is used with decision making statement such as if...else.
EX:-
#include <stdio.h>
int main () {
int a = 10;
do {
if( a == 15) {
a = a + 1;
continue;
}
} while( a < 20 );
return 0;
}