1 DecisionControl
1 DecisionControl
return 0;
}
Exercise
/* Determine the output of the following program*/
int main() {
int m=1;
if(m==1)
{
printf(“Delhi”);
if(m==2) {
printf(“Chennai”);
else
printf(“Bangalore”);
} else{
printf(“Ahmedabad”);
}
return 0;
}
Exercise
/* Determine the output of the following program*/
#include<studio.h>
int main() {
int code = 5;
if (code > 1)
printf(“Jerusalem”);
else
if(code < 1)
printf(“Paris”);
else
printf(“Lyon”);
return 0;
}
Exercise
int main(){
int x = 0;
if( x >=0)
if(x > 0)
printf(“Number is positive”);
else
printf(“Number is negative”);
return 0;
}
Exercise
What is the output of the
following code?
int n = 0, m;
for(m=1; m<=n+1; m++){
printf(“%d”, m);
}
Exercise
Write a for statement to print
each of the following sequence
of integers:
(a)1,2,4,8,16,32
(b)1,3,9,27,81,243
(c)-4, -2,0,2,4
(d)-10,-12,-14,-18,-26,-42
Exercise
What is the output of the following code?
int main(){
int i;
for(i=1;i<=5; printf(“%d”,i))
i = i+1;
return 0;
}
Exercise
What is the output of the following program?
main()
{
int m[] = {1,2,3,4,5};
int x, y=0;
for(x=0;x<5;x++)
y = y + m[x];
printf(“%d”, y);
}
Exercise
#include<stdio.h>
int main() {
int num[40],i;
for(i=0;i<=100; i++)
num[i] = i;
return 0;
}
Exercise : Output?
Exercise: Output?
Exercise
• Define a structure type, struct personal
that would contain person name, date of
joining and salary. Using this structure, write a
program to read this information for one
person from the keyboard and print on the
screen.
Exercise
Define a structure called cricket that will describe the
following information:
player name
team name
batting average
Using cricket, declare an array player with 50
elements and write a program to read information
about all the 50 players and print team-wise list
containing names of players with their batting average.
Exercise
Define a structure data type called
time_struct containing three members
integer hour, integer minute and
integer second. Develop a program that
would assign values to the individual members
and display the time in the following format.
16:40:51
Exercise
Define a structure names census with the following members:
– A character array city[] to store names.
– An integer to store population of the city
– A float member to store the literacy level
int i =0;
i = i + 1;
if (i <=5) {
printf("IICT");
exit (0);
main();
}
return 0;
}