Tuesday, September 2, 2014

print the following combination on the screen using for loop


Problem

Create a program that prints the following combination on the screen (console) using for loop.
1 1
1 2
2 1
3 2

Solution - Code

#include<stdio.h>
int main()
{
 int i,j;
 for(i=1;i<=3;i++)
 {
  for(j=1;j<=2;j++)
  {
   if(i==2 && j==2 || i==3 && j==1)
   continue;
   else
   {
    printf("%d%d\n",i,j);
   }
  }
 }
 system("pause");
 return 0;
}

Sample Output

combination using loop c language

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact