Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int A[20], n, i;
- int valid = 2; // 2 for unused value
- int one = 0, zero = 0;
- printf("Enter number of inputs :");
- scanf("%d", &n);
- if (n >= 2)
- {
- printf("Enter %d inputs (0 or 1) :\n", n);
- for (int j = 1; j <= n; j++)
- {
- scanf("%d", &A[j]);
- }
- for (i = 1; i <= n; i++)
- {
- switch (A[i])
- {
- case 1:
- {
- one++;
- break;
- }
- case 0:
- {
- zero++;
- break;
- }
- }
- }
- if (one == zero)
- {
- valid = 1;
- }
- else
- {
- valid = 0;
- }
- }
- else
- {
- printf("Your inputs should be atleast 2.\n");
- }
- switch (valid)
- {
- case 1:
- {
- printf("Congrats, Your string is valid \n");
- break;
- }
- case 0:
- {
- printf("Your string is not valid\n");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement