To Be Familiarize With Control Structures ( Looping )

  1. WAP to display the ASCII value of all letters from A to Z.
  2. WAP to print " SEC " 10 times in each new lines.
  3. WAP to find the sum of first 5 natural numbers.
  4. WAP to count only positive numbers out of 10 integers no you entered.
  5. WAP to find the power of any given number.
  6. WAP to enter the numbers until the user enters 5 positive numbers and find the average.
  7. WAP to print the Fibonacci series up to n terms.


====================================================================
1.)  Question 1
#include <stdio.h>
#include <conio.h>
void main ()
{
char i=65;
char ch='A';
clrscr ();
for(i=65;i<91;i++)
{
printf ("Ascii value of%c = %d\n",ch,ch);
ch=ch+1;
}
getch ();
}

====================================================================
2.)  Question 2
#include <stdio.h>
#include <conio.h>
void main ()
{
int i;
clrscr ();
for (i=1;i<=10;i++)
{
printf ("Sec\n");
}
getch ();
}

====================================================================
3.)  Question 3

#include <stdio.h>
#include <conio.h>
void main ()
{
int i,s=0;
clrscr ();
for (i=1;i<=5;i++)
{
s=s+i;
}
printf ("The sum is %d",s);
getch ();
}

====================================================================
4.)  Question 4


#include <stdio.h>
#include <conio.h>
void main ()
{
int i,c=0,x;
clrscr ();
printf ("Enter 10 integer number\n");
for (i=1;i<=10;i++)
{
scanf ("%d",&x);
if (x>=0)
c=c+1;
}
printf ("There are %d positive numbers.",c);
getch ();
}


====================================================================
5.)  Question 5

#include <stdio.h>
#include <conio.h>
void main ()
{
int i,b,e,r=1;
clrscr ();
printf ("Enter base\n");
scanf ("%d",&b);
printf ("Enter power to base\n");
scanf ("%d",&e);
for (i=1;i<=e;i++)
{
r=r*b;
}
printf ("The result is %d",r);
getch ();
}

====================================================================
6.)  Question 6

#include <stdio.h>
#include <conio.h>
void main ()
{
int i,x,s=0,pc=0;
float a;
clrscr ();
printf ("Enter a number\n");
for (i=1;pc<5;i++)
{
//printf ("Enter a number\n");
scanf ("%d",&x);
if (x>0)
{
pc=pc+1;
s=s+x;
}
/*else
printf ("Try again\n");*/
}
a=s/5.0;
printf ("The average is %f",a);
getch ();
}

====================================================================
7.)  Question 7

#include <stdio.h>
#include <conio.h>
void main ()
{
int i=1,t,a=0,b=1,c=0;
clrscr ();
printf ("Enter a term: ");
scanf ("%d",&t);
/*a=0;
b=1;
c=0;*/
for (i=1;i<=t;i++)
{
printf ("%d, ",c);
a=b;
b=c;
c=a+b;
}
getch ();
}

No comments