Skip to main content

Posts

Showing posts from July, 2013

Wap to find the nth term of the following series__ 1,2,2,4,4,4,4,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16......................................

#include<stdio.h> #include<math.h> void main() {     int a=1,b=1,c,n;     printf("enter the no for which u want the term");     scanf("%d",&n);     while(a<n)         a=a+pow(2,b++);     c=pow(2,--b);     if((c<=n)&&(n<=a))         printf("\n%d",c); } NOTE-  i have compiled this program in  codeblocks  if u do it in turbo c++  use   conio.h   header file in the beginning  and  getch()   a the  last.

Wap to count the number of occurrences of a particular word in the string.

#include<stdio.h> #include<conio.h> #include<string.h> void main() {     int a,b=0,count=1,i,j,c;     char name1[1000],name2[1000];     printf("enter the string \n");     gets(name1);     printf("enter the word that u want to search in the string\n");     gets(name2);     a=strlen(name2);     for(i=0;name1[i]!='\0';i++)     if(name1[i]==name2[0])     {         c=i,count=1;         for(j=1;j<a;j++)         if(name1[++c]==name2[j])         count++;         if(count==a)         b++;     }     printf("the word occures %d times in the string",b);     getch(); }

How to install Code Blocks?

you may be thinking why  have i written a post for installing code blocks as it is very easy to install programs on windows  now a days may be a child studying in grade 3 would be able to do it, but there are somethings we always overlook which leads to a severe problem that we are not able to compile c code snippets on code blocks. So here is the right process. 1) first go to the download website of code blocks i.e http://www.codeblocks.org/downloads/26#windows 2)you will get this type of window now here  download the 98 mb  file named   codeblocks-12.11mingw-setup.exe. 3) now after downloading the file install the file and then open code blocks  then goto settings then select compiler  there select   toolchain executables then in the the compilers directory click the auto detect button and then click ok , and that's it ,now code blocks is ready to compile and run c code snippets.

wap to print the following pattern.

#include<stdio.h> void main() { int i,j,k,a=1,b=1,n; printf("enter the number of rows"); scanf("%d",&n); for(i=n;i>=1;i--)  {    {     for(j=1;j<=i-1;j++)     printf("  ");     for(k=1;k<=b;k++)     if((k&1)==0)     printf("  ");     else     printf("%c ",'a');     }   b=b+2;   printf("\n");   } } NOTE-  i have compiled this program in  codeblocks  if u do it in turbo c++  use   conio.h   header file in the beginning  and  getch()   a the  last

wap to print the following pattern....

#include<stdio.h> void main() { int i,c=1,a=1,n; printf("enter the no of rows"); scanf("%d",&n); for(i=1;i<=n;i++) { if((i&1)==0)    {     for(c=1;c<=i;c++)     if((c&1)==0)     printf("%d ",1);     else     printf("%d ",0);     } else     {     for(a=1;a<=i;a++)     if((a&1)==0)     printf("%d ",0);     else     printf("%d ",1);     } printf("\n"); } }

wap to print the following pattern.

                                      #include<stdio.h> void main() { int i,j,n,a=1,k,m,b=1; printf("enter the no. of rows"); scanf("%d",&n); for(i=n;i>=1;i--) {  {  for(j=1;j<=i-1;j++)  printf("  ");  for(k=b;k<=a;k++)  printf("%d ",k);  for(m=a-1;m>=b;m--)  printf("%d ",m);  }  printf("\n");  a=a+2;  b=b+1;  } } NOTE-  i have compiled this program in  codeblocks  if u do it in turbo c++  use   conio.h   header file in the beginning  and  getch()   a the  last