Nakum Anil

PRACTICAL-SET—2

2_1.c
Write a program to display multiplication table.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,T=0,n;
clrscr();
printf("Table of=");
scanf("%d",&n);
for(i=1;i<=10;i++)
   {
   T=n*i;
   printf("\n\n\t\t%d*%d=%d",n,i,T);
   }
getch();
}



2_2.c
Write a program to print 1+1/2+1/3+1/4+………+1/N series.

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
float i,sum=0;
clrscr();
printf("Series up to ");
scanf("%d",&n);
for(i=1;i<=n;i++)
   {
   sum=sum+1/i;
   }
    printf("\tAddition of sirirs=%f",sum);
getch();
}



2_3.c
 Write a program to find sum of all integers greater than 100 & less than 200 and are divisible by 5.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,k=0;
clrscr();
for(i=100;i<=200;i++)
   {
   if(i%5==0)
     {
      k=k+i;
     }
   }
   printf("\nAddition is=%d",k);
getch();
}



2_4.c
The distance between two cities (In KM) is input through key board. Write a program to convert and print this distance in meters, feet, inches & centimeters.

#include<stdio.h>
#include<conio.h>
void main()
{
long double D,m,cm,I,F;
clrscr();
    printf("Enter the Distance between two city in K.M. D=");
    scanf("%Lf",&D);
  m=D*1000;
    printf("\nDistance between two city in meter m=%Lf",m);
  cm=D*100*1000;
    printf("\n\nDistance between two city in C.M. cm=%Lf",cm);
  I=D*39370.07874;
    printf("\n\nDistance between two city in Inch I=%Lf",I);
  F=D*3280.8399;
    printf("\n\nDistance between two city in feet F=%Lf",F);
getch();
}



2_5.c
Write a program to find sum of first N odd numbers. Ex. 1+3+5+7+………..+N.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("Enter the value n=");
scanf("%d",&n);
for(i=1;i<=n;i++)
   {
   printf("\n\n\t%d",i);
   if(i%2!=0)
   sum=sum+i;
    }
     printf("\nAddition of Od num. in n=%d",sum);
getch();
}

No comments:

Post a Comment