Posts

Showing posts from November, 2011

Number Magic2 Using For loop #c

The Output look like this 1 2 3 4 5 6 7 8 9 10 //Lets start the program #include<stdio.h> #include<conio.h> void main() { int j,k,b=31,c; clrscr(); for(c=9;c>=1;c=c-1,b=b+1)    {printf("\n");     for(j=1;j<=b;j++)     printf(" ");     for(k=1;k<=c;k++)     printf("%d ",c);     }     getch();     } Lets Start Next Program. The Out Will look like this.                                                    1                                                  2  3                                                4  5  6                                              7  8  9  10 //Lets Start the program. #include<stdio.h> #include<conio.h> void main() { int i,j,k,a=40; clrscr(); for(i=1;i<=9;i++,a=a-1)    {printf("\n");     for(j=1;j<=a;j++)     printf(" ");     for(k=1;k<=i;k++)     printf("%d ",i);     }     getch();     }

Number Magics using For loop #c

The program to get output like this 1 2 2 3 3 3 4 4 4 4 //It's a simple program.Here we print only 9 rows. #include<stdio.h> #include<conio.h> void main() { int i,n=9,k; //Now we use this for loop to check the number of rows. for(i=1;i<=n,i++) //Here we use this for loop to print like 1 or 2 2 or 3 3 3.      { for (k=1;k<=i;k++)               printf("%d",i);       } getch(); }

Fibonacci Series using For loop #c

The Fibonacci Series is like  0,1,1,2,3,5,8,13------------ or 0 ,  0+1, 1+1 ,2+1, 3+2, 5+3, 8+5 // A program to display Fibonacci Series using For loop in c. #include<stdio.h> #include<conio.h> void main() { int n,i,x=1,y=0,z=0; clrscr(); printf("Enter the limit\n"); scanf("%d",&n); for (i=1;i<=n;i++)     { printf("%d,",z);       z=x+y;       x=y;       y=z;       }       getch();       }

Factorial Of a Number Using For loop

//Factorial of a Number Using For loop in C. #include<stdio.h> #include<conio.h> void main() { int n,i,f; clrscr(); printf("Enter a Number\n"); scanf("%d",&n); for(i=1,f=1;i<=n;i++)    {f=f*i;}    printf("The factorial is %d",f);    getch();    } //Multiplication table of a user defined number using for loop in C. #include<stdio.h> #include<conio.h> void main() { int i,n,p; clrscr(); printf("Enter a number\n"); scanf("%d",&n); for (i=1;i<=10;i++)     {p=i*n;      printf("%d X %d = %d\n",n,i,p);      }      getch();      } //Multiplication table of All numbers up to 10 using for loop in C. #include<stdio.h> #include<conio.h> void main() { int n,i,p,j; clrscr(); for (i=1;i<=10;i++)     {printf("The multiplication table of %d\n",i);     printf("\n");      for(j=1;j<=10;j++)     { p=i*j;      printf("%d X %d =

For Loop

Image
 Now i am talking about "for loop". For loop is similar to while loop. You can use while loop instead of for loop and also while loop instead of while loop. The Synatax of for loop is  for(initiation;condition;statement)

To print a given number is odd or even. #c

//The Program by Tittu Varghese #include<stdio.h> #include<conio.h> void main() { int x,a; clrscr(); printf("Enter a number\n"); scanf("%d%",&x); a = x%2; if (a==0)     printf("The given number %d is even.",x); else     printf("The given number %d is odd.",x); getch(); }

Largest value of set of given numbers using while loop #c

//The Program Written by Tittu Varghese //To find largest of set of given numbers using while loop. #include<stdio.h> #include<math.h> #include<conio.h> void main() { int x,l=-32768,i=1,n; clrscr(); printf("Enter the limit\n"); scanf("%d",&n); x=l; printf("Then enter %d numbers\n",n); while(i<=n)  {   scanf("%d",&x);   if (x>l)     l=x;     i=i++;  } printf("The largest of given %d numbers is %d",n,l); getch(); } //Here we assign value for "l" as -32768 because it is the smallest value can assign to int (intiger). //*We can use if,else etc. with while,for etc. loops.   //The Program Written by Tittu Varghese //To find largest and smallest of set of given numbers using while loop. #include<stdio.h> #include<math.h> #include<conio.h> void main() { int x,l=-32768,s=32767,i=1,n; clrscr(); printf("Enter the limit\n"); scanf(&

Sum and average of set of given numbers using while loop #c

//The Program By Tittu Varghese // To display the sum and average of set of given numbers. #include<stdio.h> #include<math.h> #include<conio.h> void main() { int x,i=1,s=0,n; float a; clrscr(); printf("Enter the limit\n"); scanf("%d",&n); printf("Enter %d numbers\n",n); while(i<=n)  {   scanf("%d",&x);   s = s+x;   i=i++;  } printf("sum of given %d given number is %d and\n",n,s); a =s/n; printf("The average is %f\n",a); getch(); } //getch(); is used for hold the out put screen. //clrscr(); is used for clear the screen. //***it must use after variable declaration.