Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(){
  3. int A[20],n,i;
  4. int valid = 2; // 2 for unused value
  5. int count = 0;
  6. printf("Enter number of inputs :");
  7. scanf("%d",&n);
  8. if(n >= 2){
  9. printf("Enter %d inputs (0 or 1) :\n", n);
  10. for (int j = 1; j <= n; j++)
  11. {
  12. scanf("%d", &A[j]);
  13. }
  14. for (i = 1;i <= n;i++){
  15. switch(A[i]){
  16. case 1:
  17. {
  18. count++;
  19. break;
  20. }
  21. case 0:
  22. {
  23. count++;
  24. break;
  25. }
  26. }
  27. }
  28. if (count%3 == 0)
  29. {
  30. valid = 1;
  31. }
  32. else
  33. {
  34. valid = 0;
  35. }
  36. }
  37. else{
  38. printf("Your inputs should be atleast 2.\n");
  39. }
  40. switch(valid){
  41. case 1:
  42. {
  43. printf("Congrats, Your string is valid \n");
  44. break;
  45. }
  46. case 0:
  47. {
  48. printf("Your string is not valid\n");
  49. break;
  50. }
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement