Thursday, September 19, 2013

EXERCISE CHAPTER NO. 3 " LOOPS"

EXERCISE CHAPTER NO. 3 " LOOPS"

Chapter No. 3: Question No.  9

#include<stdio.h>
#include<conio.h>
void main(void)
{
                                clrscr();
                                long int on=0;
                                float en=1;
                                for(int i=1;i<=30;i++)
                                {
                                                if(i%2!=0)
                                                {
                                                on+=i;
                                                }
                                                else
                                                {
                                                en*=i;
                                                }
                                }
                                printf("Sum of Odd Numbers = %ld\n",on);
                                printf("Product of Even Numbers = %.0f",en);
                                getch();
}


Chapter No. 3: Question No. 10(A)

#include<stdio.h>
#include<conio.h>
void main(void)
{
                                clrscr();
                                int a,i,r;
                                printf("Enter an integer value = ");
                                scanf("%d",&a);
                                for(i=10;i>=1;i--)
                                {
                                r=a*i;
                                printf("%d * %d = %d\n",a,i,r);
                                }
                                getch();
}

Chapter No. 3:  Question No. 10(B)
#include<stdio.h>
#include<conio.h>
void main(void)
{
                                clrscr();
                                int a,i,r;
                                printf("Enter an integer value = ");
                                scanf("%d",&a);
                                i=10;
                                while(i>=1)
                                {
                                r=a*i;
                                printf("%d * %d = %d\n",a,i,r);
                                i--;
                                }
                                getch();
}

Chapter No. 3:  Question No. 11

#include<stdio.h>
#include<conio.h>
void main(void)
{
                                clrscr();
                                int i,r;
                                printf("Number\tSquare\n");
                                printf("------\t------\n");
                                for(i=1;i<=10;i++)
                                {
                                r=i*i;
                                printf("%d\t%d\n",i,r);
                                }
                                getch();

}

No comments:

Post a Comment