Showing posts with label Problem. Show all posts
Showing posts with label Problem. Show all posts

C Program The Bus Driver Problem

How to write a C Program to The Bus Driver Problem in C Programming Language ?


C Program The Bus Driver Problem.

  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int i,j,n,d,r,sum,y;
  6.     int x[120][120];
  7.  
  8.     while(scanf("%d%d%d",&n,&d,&r)!=EOF)
  9.     {
  10.         if(n==0 && d==0 && r==0)
  11.             break;
  12.         y=0;
  13.  
  14.         for(i=0;i<2;i++)
  15.         {
  16.             for(j=0;j<n;j++)
  17.             {
  18.                 scanf("%d",&x[j][i]);
  19.             }
  20.         }
  21.           for(i=0;i<n;i++)
  22.           {
  23.             sum=0;
  24.             for(j=0;j<2;j++)
  25.             {
  26.               sum=sum+x[i][j];
  27.             }
  28.             if(sum<d)
  29.             y=y+0;
  30.             else
  31.             {
  32.                 y=y+((sum-d)*r);
  33.             }
  34.         }
  35.         printf("%d\n",y);
  36.     }
  37. return 0;
  38. }

Skittles problem C Program

How to write a C Program to Skittles problem in C Programming Language ?

Hashmat the brave warrior C Program

Hashmat the brave warrior

Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before fighting he just calculates one thing, the difference between his soldier number and the opponent's soldier number. From this difference he decides whether to fight or not. Hashmat's soldier number is never greater than his opponent.