0% found this document useful (0 votes)
52 views25 pages

1 DecisionControl

The main function will print "IICT" infinitely and never return 0 since the program calls main() recursively inside the if statement without changing the value of i.

Uploaded by

Meet Munjapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views25 pages

1 DecisionControl

The main function will print "IICT" infinitely and never return 0 since the program calls main() recursively inside the if statement without changing the value of i.

Uploaded by

Meet Munjapara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Exercise

/* Determine the output of the following program*/


int main() {
int i=2; //Variable declaration
if(i== 1)
printf(“ABC”);
else {
if(i==2)
printf(“PQR”);
else
printf(“XYZ”);
}
return 0;
}
Exercise
/* Determine the output of the following program*/
int main() {
int a = 10, b= 5;
if(a>b)
{
if(b > 5)
printf(“%d”, b);
}
else
printf(“%d”, a);

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

Write a program to do the following:

• To read details of 5 cities randomly using an array variable.


• To sort the list alphabetically
• To sort the list based on literacy level
• To sort the list based on the population
• To display sorted lists.
Exercise
Define a structure that can describe an hotel. It
should have members that include the name, address,
grade, average room charge, and number of rooms.

Write a program to perform the following operations:


– To print out hotels of a given grade in order of charges.
– To print out hotels with room charges less than a give
value.
Exercise
Exercise
Exercise
Exercise
Exercise
Determine the output of the following program?
int main(){
int x=10;
int y=20;
int p,q;
p = prod(x, y);
q = prod(p, prod(x,y));
printf(“%d %d”, p,q);
return 0;
}

int prod(int a, int b) {


return a*b;
}
Exercise
Exercise
Exercise
int main() {

int i =0;
i = i + 1;

if (i <=5) {
printf("IICT");
exit (0);
main();
}
return 0;
}

You might also like