To Be Familiarize With The Concept of Nested Looping Structures
- WAP to enter the marks of 3 subjects for each students and find the highest total marks out of 3 students.
- WAP to display all the Armstrong Numbers from 100 to 1000 and display total no of it.
- WAP to display all the Primes Numbers between 10 to 100.
- WAP to find sum (sum=1+x^2/2!-x^4/4!+.....to n terms)
- WAP to find sum ( sum=x-x^3/3!+x^5/5!-..................)
- WAP to print following patterns:
* ******* *
** * * ***
*** ******* *****
****
=========================================================================================
1.) Question 1
#include <stdio.h>
#include <conio.h>
void main ()
{
int i,j,h,m,s=0;
clrscr ();
h=s;
for (i=1;i<=3;i++)
{
printf ("Enter marks:\n");
s=0;
for (j=1;j<=3;j++)
{
scanf ("%d",&m);
s=s+m;
if (s>h)
h=s;
}
}
printf ("The highest is %d",h);
getch ();
}
====================================================================
2.) Question 2
#include<stdio.h>
#include <conio.h>
void main()
{
int n,r,s,t,c=0;
clrscr ();
for(n=100;n<=1000;n++){
t=n;
s = 0;
while(t!=0){
r=t%10;
t=t/10;
s=s+(r*r*r);
}
if(s==n)
{c=c+1;
printf("%d ",n);}
}
printf ("\nThe total armstrong no. is %d",c);
getch ();
}
=====================================================================
3.) Question 3
#include <stdio.h>
#include <conio.h>
void main ()
{
int i,j,t,c=0;
clrscr ();
for (i=10;i<=100;i++)
{
t=i;
c=0;
for (j=1;j<=t;j++)
{
if (t%j==0)
c=c+1;
}
if (c==2)
printf ("%d, ",t);
}
getch ();
}
==================================================================
4.) Question 4
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ()
{
int i,j,x,n,sign=1;
float t,s=1.0,p=2.0,f=1.0;
clrscr ();
printf ("Enter the value of x & n.\n");
scanf ("%d%d",&x,&n);
for (i=1;i<n;i++)
{
f=1;
for (j=1;j<=p;j++)
{
f=j*f;
}
t=sign*pow(x,p)/f;
s=s+t;
p=p+2.0;
sign=sign*(-1);
}
printf ("The sum is %f",s);
getch ();
}
=======================================================================
5.) Question 5
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ()
{
int i,j,x,n;
float t,s,p=1.0,f;
clrscr ();
printf ("Enter the value of x & n.\n");
scanf ("%d%d",&x,&n);
for (i=1;i<=n;i++)
{
f=1.0;
for (j=1;j<=p;j++)
{
f=j*f;
}
t=(pow(-1,i-1)*(pow(x,p)/f));
s=s+t;
p=p+2;
}
printf ("The sum is %f",s);
getch ();
}
======================================================================
6.( i )) Question 6 ( a )
#include <stdio.h>
#include <conio.h>
void main ()
{
int i,j;
clrscr ();
for (i=1;i<=4;i++)
{
for (j=1;j<=4;j++)
{
if (j<=i)
printf ("*");
else
printf (" ");
}
printf ("\n");
}
getch ();
}
========================================================================
6.( ii )) Question 6 ( b )
#include <stdio.h>
#include <conio.h>
void main ()
{
int i,j;
clrscr ();
for (i=1;i<=3;i++)
{
for (j=1;j<=7;j++)
{
if (i==2&&j>1&&j<7)
printf (" ");
else
printf ("*");
}
printf ("\n");
}
getch ();
}
===================================================================
6.( iii )) Question 6 ( c )
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,k=0;
clrscr ();
for(i=1; i<=3; i++, k=0)
{
for(j=1; j<=3-i; j++)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}
getch ();
}
No comments