upsidedown

DAA Expt1 Pranav

Jan 19th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.84 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int count;
  4.  
  5. int main()
  6. {
  7.  
  8.     int i,a,b;
  9.     a=5;
  10.     b=6;
  11.     count+=3;
  12.  
  13.     for(i=0;i<10;i++)
  14.     {
  15.         count++;
  16.         printf("  %d",a);
  17.         a=a+b;
  18.         count+=2;
  19.     }
  20.     count++;
  21.  
  22.     printf("\n Count  is %d \n",count);
  23. }
  24.  
  25.        
  26.  
  27.  
  28.   5  11  17  23  29  35  41  47  53  59
  29.  Count  is 34
  30. Press any key to continue
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. //find max and min of 3
  50.  
  51. #include<stdio.h>
  52.  
  53. int count;
  54.  
  55. int main()
  56. {
  57.     int a,b,c;
  58.     printf("Enter the 3 nos");
  59.     scanf("%d %d %d",&a,&b,&c);
  60.    
  61.     count+=3;
  62.  
  63.     if(a>b && a>c)
  64.     {
  65.         printf("\nthe biggest no is %d",a);
  66.         count+=2;
  67.     }
  68.     else if(b>c && b>a)
  69.     {
  70.         printf("\nthe biggest no is %d",b);
  71.         count+=3;
  72.     }
  73.     else
  74.     {
  75.         printf("\nthe biggest no is %d",c);
  76.         count+=3;
  77.     }
  78.  
  79.     printf("\n count= %d ",count);
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. Output:
  90. BEST CASE
  91. Enter the 3 nos3 2 1
  92.  
  93. the biggest no is 3
  94.  count= 5 Press any key to continue
  95.  
  96.  
  97.  
  98. WORST CASE
  99. Enter the 3 nos1 2 3
  100.  
  101. the biggest no is 3
  102.  count= 6 Press any key to continue
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. //search
  124. #include<stdio.h>
  125.  
  126. int count;
  127.  
  128. int main()
  129. {
  130.  
  131.     int i,srch,a[10]={1,2,5,6,8,9,7,17,15,28},flag=0;
  132.    
  133.     printf("enter the number to search");
  134.     scanf("%d",&srch);
  135.     count+=3;
  136.  
  137.  
  138.    
  139.     for(i=0;i<10;i++)
  140.     {
  141.         count++;
  142.  
  143.         if(a[i]==srch)
  144.         {
  145.             printf("Element found at position %d ",i+1);
  146.             flag=1;
  147.             count+=3;
  148.             break;
  149.         }
  150.         count++; // incremented for the if
  151.  
  152.     }
  153.  
  154.     count++; // incremented for the for
  155.  
  156.     if(flag==0)
  157.     {
  158.         printf("Not Found");
  159.         count++;
  160.     }
  161.  
  162.     count++; // incremented for the if
  163.  
  164.  
  165.     printf("\n Count  is %d \n",count);
  166. }
  167.  
  168.        
  169.  
  170.  
  171. OUTPUT:
  172. BEST CASE
  173.  
  174. enter the number to search1
  175. Element found at position 1
  176.  Count  is 9
  177. Press any key to continue
  178.  
  179.  
  180.  
  181. WORST CASE
  182. enter the number to search28
  183. Element found at position 10
  184.  Count  is 27
  185. Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment