C Programming : Iterative Statements (BIM-TU)

By Ashesh Neupane

  1. WAP to display all numbers 100 to 200 that end with 0 or 1.
#include<stdio.h>
int main()
{
    int i;
    for(i=100;i<=200;i++)
    {
        if(i%10==0 || i%10==1)
        {
            printf("%d ",i);
        }
    }
    return 0;
}
100 101 110 111 120 121 130 131 140 141 150 151 160 161 170 171 180 181 190 191 200

2. Write a program to display the following series:

*
**
***
****
*****

#include<stdio.h>
int main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

3. Write a program to display the following series:

image
#include<stdio.h>
int main()
{
    int i,j,k,sp=3;
    for(i=1;i<=7;i=i+2)
    {
        for(k=1;k<=sp;k++)
        {
            printf(" ");
        }
        for(j=1;j<=i;j++)
        {
            printf("*");
        }
        printf("\n");
        sp--;
    }
    return 0;
}

4. Write a program to display the following series:

5
45
345
2345
12345

#include<stdio.h>
int main()
{
    int i,j;
    for(i=5;i>=1;i--)
    {
        for(j=i;j<=5;j++)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

5. Write a program to display the following series:

image 1
#include<stdio.h>
int main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5-i;j++)
        {
            printf(" ");
        }
        for(j=i;j>=1;j--)
        {
            printf("%d", j);
        }
        for(j=2;j<=i;j++)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

6. Write a program to display the following series:

image 2
#include<stdio.h>
int main()
{
 int i,j,k,sp=0;
 for(i=7;i>=1;i=i-2)
 {
 for(k=1;k<=sp;k++)
 {
 printf(" ");
 }
 for(j=1;j<=i;j++)
 {
 printf("*");
 }
 printf("\n");
 sp++;
 }
 return 0;
}

7. Write a program to display the following series:

1
10
101
1010
10101

#include<stdio.h>
int main()
{
 int i,j;
 for(i=1;i<=5;i++)
 {
 for(j=1;j<=i;j++)
 {
 printf("%d",j%2);
 }
 printf("\n");
 }
 return 0;
}

8. Write a program to enter a number and count the number of digits.

#include<stdio.h>
int main()
{
    int n,b;
    printf("Enter any number:");
    scanf("%d",&n);
    while(n>0)
    {
        b++;
        n = n/10;
    }
    printf("No. of digits = %d", b);
}
Enter any number: 300
No. of digits = 3

9. Write a program to display all prime numbers between 100 to 200.

#include<stdio.h>
int main()
{
 int n,i,x;
 for(n=100;n<=200;n++)
 {
 x=0;
 for(i=2;i<=n/2;i++)
 {
 if(n%i==0)
 {
 x=1;
 break;
 }
 }
 if(x==0)
 printf("%d ",n);
 }
 return 0;
}
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199

10. Write a program to display all palindrome numbers between 100 to 500.

#include<stdio.h>
int main()
{
    int i,j,a;
    for(i=1;i<=4;i++)
    {
        for(j=0;j<=9;j++)
        {
            a = (100*i)+(10*j)+i;
            printf("%d ", a);
        }
    }
    return 0;
}
101 111 121 131 141 151 161 171 181 191 202 212 222 232 242 252 262 272 282 292 303 313 323 333 343 353 363 373 383 393 404 414 424 434 444 454 464 474 484 494

Ashesh Neupane is the Co-Founder and Former Admin of HighApproach. He is also a student of Bachelor of Information Management (BIM) at Tribhuvan University.

Leave a Comment

Slide to prove you're not a bot/spammer *