Entering Compiling and Running C Programs Problem 1 A program is required which prints all the odd numbers from 0 to 25.

Authors Avatar

Section A

Entering –Compiling and Running C Programs

Problem 1

A program is required which prints all the odd numbers from 0 to 25.

  /*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=1;

  clrscr();

  do

        {

  printf("%d",START);

  START=START+2;

        }while(START<=25);

  getch();

  }

        Output  of the above program

Modify the Program:

    *To print the even numbers between 0 and 25.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=2;

  clrscr();

  do

        {

  printf("%d",START);

  START=START+2;

        }while(START<25);

  getch();

  }

Output of the above program

Modify the Program:

 *To print the even numbers between 0 and 50.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=2;

  clrscr();

  do

        {

  printf("%d                ",START);

  START=START+2;

        }while(START<=50);

  getch();

  }

Output of the above program

Modify the Program:

         *To print the odd numbers between 15 and 35 along one line separated by a comma.

/*****************

  *Problem Number 1*

  ******************/

        #include<stdio.h>

  void main()

  {

  int START=15;

  clrscr();

  do

        {

  printf("%d,",START);

  START=START+2;

        }while(START<=35);

  getch();

  }

 

Output of the above program

What is the purpose of the function getch()?

It gets the characters on the screen what the program  has to execute.

Problem 2

Write a program to determine if a given integer number  is dividable by 3

/******************

   *Problem Number 2*

   ******************/

  #include<stdio.h>

  void main()

  {

  int N;

  float R;

  clrscr();

  printf("Enter an integer Number: \n");

  scanf("%d",&N);

  R=N % 3;

  if(R==0)

           {

                printf("%d is dividable by 3. \n" ,N);

           }

  else

           {

                printf("%d is NOT dividable by 3. \n",N);

           }

  getch();

  }

Output of the above program

Modify the Program to determine if a given number is dividable by 5.

       /******************

   *Problem Number 2*

   ******************/

  #include<stdio.h>

  void main()

  {

  int N;

  float R;

  clrscr();

  printf("Enter an integer Number: \n");

  scanf("%d",&N);

  R=N % 5;

  if(R==0)

           {

                printf("%d is dividable by 5. \n" ,N);

           }

  else

           {

                printf("%d is NOT dividable by 5. \n",N);

           }

  getch();

  }

Output of the above program

Explain the purpose of the symbol ‘%’ in the program?

It functions like ‘/’, the symbol divides the numbers,when the reminder is 0 the output will be

“Dividable” otherwise” NOT dividable”.

Join now!

What is 5 % 3=?

That is 5/3.If we modify the above program like this the output  will be 5 is NOT dividable by 3,

Because the reminder is not Zero.

       Problem 3

Write a program to print the square and cube of given integer number.

      /******************

       *Problem Number 3*

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

#include<stdio.h>

void main(void)

{

int N,sq,cube;

clrscr();

printf("Enter an integer Number: \n");

scanf("%d",&N);

sq=N*N;

cube=N*N*N;

printf("%d * %d= %d\n",N,N,sq);

printf("%d * %d * %d= ...

This is a preview of the whole essay