You are on page 1of 5

EDISON G AGORAM MEMORIAL SCHOOL

Programs in page no 57: (Using switch..case)


1. Accept a character and print whether it is a vowel or not.
#include<stdio.h>
main()
{
char c;
printf("Enter an alphabet\n");
scanf("%c",&c);
switch(c)
{
case 'a':case 'e':case 'i':case 'o': case 'u': printf("It is a vowel"); break;
default: printf("It is not a vowel");
}
}
2. Find the square and cube of any number.
#include<stdio.h>
main()
{
int n,ch;
printf("Enter a number\n");
scanf("%d",&n);
printf("Press 1 to find the square, 2 to cube\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Square: %d",n*n); break;
case 2: printf("Cube: %d",n*n*n); break;
default: printf("Invalid choice");
}
}
Programs in page no 62: (Using for loop)
1. Find the multiplication table of any number
#include<stdio.h>
main()
{
int i,n;
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("%d x %d = %d\n",n,i,i*n);
}
2. Print natural numbers from 100 to 1
#include<stdio.h>
main()
{
int i;
for(i=100;i>=1;i--)
printf("%d\t",i);
}
3. Print even numbers from 200 to 250
#include<stdio.h>
main()
{
int i;
for(i=200;i<=250;i+=2)
printf("%d\t",i);
}
4. Generate the following series 53 + 63 + 73+…103
#include<stdio.h>
main()
{
int i,sum=0;
for(i=5;i<=10;i++)
{
printf("%d\t",i*i*i);
sum += i*i*i;
}
printf("Sum of series: %d",sum);
}

5. Find the factorial of first 25 natural numbers.


#include<stdio.h>
main()
{
int i,fact=1;
for(i=1;i<=25;i++)
fact *= i;
printf("Factorial: %d",fact);
}
Programs in page no 63: (Using nested for loop)
1. Generate the following series: 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
}
2. Print the multiplication table from 1,2,3,4, and 5.
#include<stdio.h>
main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=10;j++)
printf("%d x %d = %d\n",i,j,i*j);
printf("\n");
}
}
3. Generate the series: 1
#include<stdio.h> 2 2
3 3 3
main() 4 4 4 4
{ 5 5 5 5 5
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("%d",i);
printf("\n");
}
}

Programs in page no 65:


1. Read an integer and print the sum of digits.
#include<stdio.h>
main()
{
int n,sum=0;
printf("Enter a number");
scanf("%d",&n);
while(n>0)
{
sum += n%10;
n/=10;
}
printf("Sum of digits: %d",sum);
}
2. Accept an integer and print their square. Quit if the number is 0 or negative.
#include<stdio.h>
main()
{
int n=1;
while(n>0)
{
printf("Enter a number");
scanf("%d",&n);
printf("Square: %d",n*n);
}
}
3. Print the sum of square of ten natural numbers.
#include<stdio.h>
main()
{
int i=1,sum=0;
while(i<=10)
{
sum+=(i*i);
i++;
}
printf("Sum of squares of 10 Natural nos: %d",sum);
}

Programs in page no 67: (Using do..while loop)


1. Read a positive or a negative number and echo it, when zero is entered, the
program should terminate.
#include<stdio.h>
main()
{
int n=1;
do
{
printf("Enter a number: ");
scanf("%d",&n);
printf("You have entered %d \n",n);
}while(n!=0);

}
2. Read any 3 values for a variable and print the mean.
#include<stdio.h>
main()
{
int i=1,n,mean=0;
do
{
printf("Enter a number: ");
scanf("%d",&n);
mean+=n;
i++;
}while(i<=3);
printf("MEAN: %d", mean/3);
}
3. Read any 10 numbers and find the sum and average.
#include<stdio.h>
main()
{
int i=1,n,mean=0;
do
{
printf("Enter a number: ");
scanf("%d",&n);
mean+=n;
i++;
}while(i<=10);
printf("SUM: %d \n",mean);
printf("AVERAGE: %d",mean/10);
}
}

You might also like