Cognizant Logo

Asked in Cognizant

Write a program to validate a phone number consisting of only 1s and 0s.

AnswerBot
1y

The program prints a pattern of alternating 1s and 0s in a specific sequence.

  • Use a loop to iterate through the given sequence of numbers

  • Inside the loop, check the length of each number and print the c...read more

Sonali Chavan
3y

In C lang,

#include<stdio.h>

int main()

{

int i,j;

int n=5;

for(i=0;i<n;i++)

{

for(j=0;j<i;j++)

{

if((i+j)%2==0){printf("0");

}

else{

printf("1");

}

}

printf("\n");

}

return 0;

}

Help your peers!
Select
Add answer anonymously...

Top GenC Interview Questions Asked at Cognizant

Q. How willing are you to adapt to new technologies?
Q. What is the difference between delete and truncate?
Q. What is the self keyword in Python?
GenC Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits