Problem 26: Even Numbers

Print the EVEN numbers between 1 to 100 using loop.

Code: 
 

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

return 0;
}
	

Problem 27: Range

Print the numbers between 100 to 200 which are completely divisible by 3 and 5.

Code: 
 

    #include<stdio.h> 
 
int main()
{
    int i;
    for(i = 100; i <= 200; i++)
    {
        if(i%3 == 0 && i%5 == 0)
        {
            printf("%d\n",i);
        }
    }

return 0;
}
Problem 28: Star Triangle

Write a program to print the following output using loop.

Code: 
 

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

return 0;
}
Problem 29: Multiplication

Take an integer as input and print it’s multiplication table up to 10. If user gives 5, your output should look like the following example-

5 * 1 = 5

5 * 2 = 10

5 * 3 = 15

.

.

.

5 * 10 = 50

Code: 
 

    #include<stdio.h> 
 
int main(){

    int n,i;
    printf("Enter the input number: \n");
    scanf("%d",&n);
    printf("********* Multiplication Table of %d *************\n",n);
    for(i = 1; i <= 10; i++)
    {
        printf("%d x %d = %d\n",n,i,n*i);
    }

return 0;
}
Problem 30: Series sum

Write a program which will print the summation of the given series-

101 + 99 + 97 + …….. + 3 + 1 = ?

Code: 
 

    #include<stdio.h> 
 
int main(){

  int i, sum = 0;
  for(i = 101; i >= 1; i -= 2)
  {
      sum=sum+i;
  }
  printf("%d\n",sum);

return 0;
}
Problem 31: Pattern I

Write a program to program to print the following output using loop-

*

Blank Line

* * *

Blank Line

* * * * *

Blank Line

* * * * * *

Code: 
 

    #include<stdio.h> 
 
int main()
{
    int i,j;
    for(i = 1; i <= 7; i++)
    {
        for(j=1;j<=i;j++)
        {
            if(i%2==0)
            {
                printf("Blank Line");
                break;
            }
            else
            {
                printf("*");
            }
        }
        printf("\n");

    }
}
Problem 32: Pattern II

Write a program to print the following output using loop.

* * * *

* * *

* *

*

Code: 
 

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

return 0;
}
Problem 33: Number Art

Write a program to print the following output using loop-

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

Code: 
 

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

return 0;
}
Problem 34: Alphabets

Write a program to display “A” to “Z” using loop .

Code: 
 

    #include<stdio.h> 
 
int main()
{
    char var;
    for(var = 'A'; var <= 'Z'; var++)
    {
        printf("%c ",var);
    }

return 0;
}

Problem 35: Square Sum

Print the summation of squares of all numbers from 5 to 25.

25 + 36 + 49 + 64 …… + 576 + 625 = ?

Code: 
 

    #include<stdio.h> 
 
int main()
{
    int i, sum = 0;
    for(i = 5; i <= 25; i++)
    {
        sum = sum +(i * i);
    }
    printf("%d\n",sum);

return 0;
}
Problem 36: Loop & Conditions

Write a program which will take an integer N from user and print all the numbers between N to -32. Stop your program when user will give N= -1 as input.

Code: 
 

    #include<stdio.h> 
 
int main()
{
   int n, i;

   while(1){
    printf("\nEnter the value of N [input -1 to stop]: \n");
    scanf("%d",&n);

    if(n == -1)
        break;
    if(n > -32){
        for(i = n; i>= -32; i--)
            printf("%d ",i);
    }else{
        for(i = n; i <= -32; i++){
            printf("%d ",i);
        }
    }
   }

return 0;
}
Problem 37: Continue and Break

Write the output of the following program-

int main(){

int i;

for(i = 10; i < 20; i++){

if(i % 2 == 0)

continue;

printf(“%d “,i);

if(i > 16)

break;

}

return 0;

}

Code: 
 

    #include<stdio.h> 
 
int main(){
    int i;
    for(i = 10; i < 20; i++){
        if(i % 2 == 0)
            continue;
        printf("%d ",i); //Output: 11 13 15 17
        if(i > 16)
            break;
    }
return 0;
}
Problem 38: Fibonacci Series

Write a program which will take an integer N as input from user and print Fibonacci series up to N. If user gives input N = 15, you should print-

0 1 1 2 3 5 8 13

Code: 
 

    #include<stdio.h> 
 
int main()
{
   int n, first = 0, second = 1;
   printf("Enter the limit N [ >= 1]: \n");
   scanf("%d",&n);

   while(first <= n){
        printf("%d ",first);
        int temp = first;
        first = second;
        second = second + temp;
   }

   return 0;
}

Problem 39: Star Pattern

Write a program to print the following output using loop.

Code: 
 

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


return 0;
}
Problem 40: Number Pattern II

Write a program to print the following output in the given format using loop-

1 1

12 21

123 321

1234 4321

12345 54321

Code: 
 

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

    return 0;
}
	

Problem 41: Average II

Find summation and average of all the numbers which are completely divisible by 3, 5 and 12 between 10 – 500. [Like 60 is divisible by all of those]

Code: 
 

    #include<stdio.h> 
 
int main()
{
    int i,sum=0,count=0;
    float avg;
    for(i=10;i<=500;i++)
    {
        if(i%3==0&&i%5==0&&i%12==0)
        {
            sum=sum+i;
            count++;
        }
    }
    avg=sum/count;
    printf("%.2f\n",avg);

    return 0;
}

Problem 42: Number Pattern III

Write a program to produce the following output using loop-

1

2 4

3 6 9

4 8 12 16

5 10 15 20 25

6 12 18 24 30 36

Code: 
 

    #include<stdio.h> 
 
int main()
{
    int i,j,k,l,m,n;
    for(i=1;i<=6;i++)
    {
        for(j=i;j<=(i*i);j=j+i)
        {
            printf("%d ",j);
        }
        printf("\n");
    }

    return 0;
}
Problem 43: Prime II

Write a program which will display all the prime numbers between 0 to N( N will be given by the user ).

If user gives N = 20, your code will print the following output-

2 3 5 7 11 13 17 19.

Code: 
 

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

    return 0;
}