Case Study Function in C (class 12) - Computer Notes | Computer Notes for 11 and 12 | PLK Computer Sir

Breaking

Home Top Ad

Post Top Ad

Responsive Ads Here

Case Study Function in C (class 12)

 Case study Function

WAP to perform following operations depending upon user’s choice. Use different function for these operations.

  1. To find maximum and minimum value stored in a list

  2. To search a number and display the position in the list.

  3. To display and count odd and even numbers present in the list separately.

  4. Exit

Use switch… case structure


/* case study proram*/

#include<stdio.h>

#include<stdlib.h>

int size;

int a[1000];

int i,choice;

void input();

void menu();

void max_min();

void search_list(); 

void display_odd_even();

int main()

{

input();

system("cls");   

    menu();

return 0;

}

void input()

{

system("cls");                                                                                                   

printf("Enter the size of array(less than 1000)\n");

scanf("%d",&size);

printf("enter elements\n");

for(i=0;i<=size-1;i++)

{

scanf("%d",&a[i]);

}

}

void menu()

{

printf("we have following menu\n");

printf("----------------------\n");

printf("1. to find maximum and minimum\n");

printf("2.to search a number\n");

printf("3. to find odd and even\n");

printf("------------------------\n");

printf("Now, enter your choice\n");

scanf("%d",&choice);

switch(choice)

{

case 1:

max_min();

break;

case 2:

search_list();

break;

case 3:

display_odd_even();

break;

default:

printf("Sorrry, you entered wrong choice....\n");

}

}

void max_min()

{

int i,max,min;

max=a[2];

min=a[1];

for(i=0;i<=size-1;i++)

{

if(max<a[i])

{

max=a[i];

}

else if(min>a[i])

{

min=a[i];

}

}

system("cls");

printf("maximum value=%d and minimum value=%d\n",max,min);

menu();

}

void search_list()

{

int i,search_number;

int flag=0;

printf("enter a number to be searched\n");

scanf("%d",&search_number);

for(i=0;i<=size-1;i++)

{

  if(a[i]==search_number)

  {

  flag=1;

  break;

  }

}

if(flag==1)

{

system("cls");

printf("%d data found in location=%d\n",search_number,i);

}

else

{

system("cls");

printf("sorry!!! the data is not in the list!!!\n");

}

menu();

}

void display_odd_even()

{

int i,odd=0,even=0;

for(i=0;i<=size-1;i++)

{

if(a[i]%2==0)

{

even++;

}

else 

{

odd++;

}

}

system("cls");

printf("total odd nos.=%d and even nos=%d\n",odd,even);

menu();

}


No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages