suraj0152

TASK0-

Jul 2nd, 2023
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | Software | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define ERROR_VALUE 0.274510
  4.  
  5. int main(){
  6. double current_var1, var2, var3, current_var4;
  7. double prev_var1=0.0;
  8. double prev_var4=0.0;
  9. int NodeCount = 0;
  10. int errorflag = 0;
  11. char infilename[100]="";
  12. char outfilename[100]="";
  13.  
  14. FILE * filein;
  15. FILE * fileout;
  16.  
  17. printf("\n enter name of the file to be read(.txt filename):");
  18.         scanf("%s",infilename);
  19.         filein = fopen(infilename, "r");
  20.  
  21. while(!feof(filein)){
  22.  
  23. fscanf(filein, "%lf %lf %lf %lf\n", &current_var1,&var2,&var3,&current_var4);
  24.  
  25.         // BLACK TO WHITE TRANSITION
  26. if ((prev_var1<0.6 && current_var1>0.6) || (prev_var4<0.6 && current_var4>0.6)) {
  27.     errorflag = 1;
  28.     }
  29.  
  30. if (errorflag) { //IF ERROR FLAG IS 1
  31.        
  32.             //If PLUS node is detected
  33.             if ((current_var1>0.6) && (current_var4>0.6)) {
  34.                 NodeCount++;
  35.                 errorflag = 0;
  36.             }
  37.             // WHITE TO BLACK TRANSITION
  38.             if ((prev_var1>0.6 && current_var1<0.6) || (prev_var4>0.6 && current_var4<0.6)) {
  39.                 NodeCount++;
  40.                 errorflag = 0;
  41.             }
  42.         }
  43.  
  44. prev_var1=current_var1;
  45. prev_var4=current_var4;
  46.  
  47. }
  48. printf("Total No Of Nodes: %d",NodeCount);
  49. return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment