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 count = 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:
- {
- count++;
- break;
- }
- case 0:
- {
- count++;
- break;
- }
- }
- }
- if (count%3 == 0)
- {
- 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