Thursday, October 24, 2013

FOLLOWING SERIES

/*WAP TO ADD 1st SEVEN TERMS OF THE FOLLOWING SERIES: (1/1!)+(2/2!)+.......+(7/7!) [using FOR loop]*/


#include<stdio.h>
#include<conio.h>
 void main()
 {
int i,j;
float fact;
float sum=0;

clrscr();
printf("\nGiven series -->\n\t\t");
printf("1/1! + 2/2! + 3/3! + 4/4! + 5/5 + 6/6! + 7/7!");
for(i=1;i<=7;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+i/fact;
}
printf("\n\n\nSum of the 1st seven terms of the given series= %f",sum);
getch();
 }

ARMSTRONG NO

/* WAP TO PRINT AND COUNT ARMSTRONG NO.S FROM 1 TO 1000.



#include<stdio.h>
#include<conio.h>
 void main()
 {
int num;
int n;
int d,sum;
int count=0;

clrscr();

printf("\nArmstrong no.s from 1 to 1000 -->\n\n\t\t");
num=1;
while(num<1000)
{
n=num;
sum=0;
while(n>0)
{
d=n%10;
sum+=d*d*d;
n=n/10;
}
if(num==sum)
{
printf("%d\t",num);
count++;
}
num++;
}
printf("\n\nTotal no. of Armstrong no.s from 1 to 1000 = %d",count);
getch();
 }

Wednesday, October 23, 2013

SUM OF ALL 3-DIGITS

//WAP TO INPUT A 3-DIGIT NO. AND CALCULATE SUM OF ALL DIGITS.


#include<stdio.h>
#include<conio.h>
void main()
{
      int num;
      int r,sum=0;
      clrscr();

      printf("\nEnter a 3-digit no.=");
      scanf("%d",&num);
      r=num%10;
      sum=sum+r;
      num=num/10;
      r=num%10;
      sum=sum+r;
      num=num/10;
      r=num%10;
      sum=sum+r;
      printf("\n\nThe sum of all digits of entered no.=%d",sum);
      getch();


}

Tuesday, October 22, 2013

MULTI-DIGITS NO.STRING

  /*WAP TO INPUT TWO MULTI-DIGITS NO.S AND COUNT NO. OF DIGITS IN BOTH NO.S .


#include<stdio.h>
#include<conio.h>
 void main()
 {
long int n1,n2;
int count1=0;
int count2=0;

clrscr();

printf("\nEnter 1st multi-digit no.(non-zero)= ");
scanf("%ld",&n1);
printf("\nEnter 2nd multi-digit no.(non-zero)= ");
scanf("%ld",&n2);

while(n1>0)
{
n1=n1/10;
count1+=1;
}
while(n2>0)
{
n2=n2/10;
count2+=1;
}

printf("\nNo. of digits in 1st no.= %d",count1);
printf("\nNo. of digits in 2nd no.= %d",count2);

if(count1==count2)
printf("\n\nBoth no.s have same no. of digits.");
else
printf("\n\nBoth no.s have different no. of digits.");

getch();
 }

Monday, October 21, 2013

ADDITION, SUBTARCTION,MULTIPLICATION, DIVISION OF TWO NO.

*WAP TO ENTER TWO NO.S AND PERFOERM ADDITION, SUBTARCTION,MULTIPLICATION, DIVISION.


#include<stdio.h>
#include<conio.h>

 void main()
 {
      float a;
      float b;      // donot input b=0, in the case of                                   division.
      float r;

      clrscr();
      printf("\nEnter 1st no.=");
      scanf("%f",&a);
      printf("\nEnter 2nd no.=");
      scanf("%f",&b);
      r=a+b;                // Here r stands for addition.
      printf("\nAddition of two no.s=%f",r);
      r=a-b;               // Here r stands for subtraction.
      printf("\nSubtraction of two no.s=%f",r);
      r=a*b;              // Here r stands for multiplication.
      printf("\nMultiplication of two no.s=%f",r);
      r=a/b;             // Here r stands for division.
      printf("\nDivision of two no.s=%f",r);
      getch();

 }

Sunday, October 20, 2013

PRINT ALL THE ASCII VALUES

1. WAP TO PRINT ALL THE  ASCII VALUES AND THEIR EQUIVALENT CHARACTERS.


(Due to space-problem on the screen, ASCII-value is only taken upto
 190. Otherwise, range of ASCII value is - [0 -255] )   */

#include<stdio.h>
#include<conio.h>
 void main()
 {
int i;

clrscr();

i=0;
while(i<=190)
{

if(i<=22)
{
printf("%d - %c\n",i,i);

}
else if(i<=46)
{
gotoxy(10,i-22);
printf("  %d - %c\n",i,i);
}
else if(i<=70)
{
gotoxy(20,i-46);
printf("  %d - %c\n",i,i);
}
else if(i<=94)
{
gotoxy(30,i-70);
printf("  %d - %c\n",i,i);
}
else if(i<=118)
{
gotoxy(40,i-94);
printf("  %d - %c\n",i,i);
}
else if(i<=142)
{
gotoxy(50,i-118);
printf("  %d - %c\n",i,i);
}
else if(i<=166)
{
gotoxy(60,i-142);
printf("  %d - %c\n",i,i);
}
else if(i<=190)
{
gotoxy(70,i-166);
printf("  %d - %c\n",i,i);
}
i++;
}
getch();
 }

Saturday, October 19, 2013

USING 3rd VARIABLE

  1. WAP TO INPUT TWO NO.S AND INTERCHANGE THEIR VALUE USING 3rd VARIABLE


#include<stdio.h>
#include<conio.h>

void main()
{
      int num1;
      int num2;
      int num3;

      clrscr();
      printf("\nEnter 1st no.=");
      scanf("%d",&num1);
      printf("Enter 2nd no.=");
      scanf("%d",&num2);
      num3=num1;
      num1=num2;
      num2=num3;
      printf("\nswapped value of num1=%d",num1);
      printf("\nswapped value of num2=%d\n",num2);
      getch();

}

3-D ARRAY

Que-: WRITE A PROGRAM OF MULTIPLICATION OF TWO MATRICES WITH 3-D ARRAY.



#include<stdio.h>
#include<conio.h>

 void main()
 {
int mat[3][3][3];
int k,i,j,l;

clrscr();

printf("For matrix 1 -->\n____________\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=0;
printf("Enter value at (%d,%d,%d)= ",k,i,j);
scanf("%d",&mat[k][i][j]);
}
}
printf("\nMatrix 1 -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=0;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}

printf("\nFor matrix 2 -->\n____________\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=1;
printf("Enter value at (%d,%d,%d)= ",k,i,j);
scanf("%d",&mat[k][i][j]);
}
}
printf("\nMatrix 2 -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=1;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=2;
mat[k][i][j]=0;
for(l=0;l<3;l++)
{
mat[k][i][j]+=mat[0][i][l]*mat[1][l][j];
}
}
}
printf("\nProduct of the above two matrices -->\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
k=2;
printf("%d\t",mat[k][i][j]);
}
printf("\n");
}
getch();
 }





2:- WAP TO CREATE A 5*5 MATRIX AND INPUT '*' IN 1st ROW & ON 2nD ROW - INPUT # & SO ON.....


#include<stdio.h>
#include<conio.h>
 void main()
 {
int mat[5][5];
int i,j;

clrscr();

printf("\nRequired pattern -->\n\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i%2==0)
printf("* ");
else
printf("# ");
}
printf("\n");
}
getch();
 }