Saturday, September 17

Print a string without using any semicolon

Write a program to print a  string without using any semicolon on the program:


#include<stdio.h>
main()
{
      if(printf("Hello.."))
      {
      }

}




I want to know how this program can modified to print any string accepted through Keyboard..!!

If anyone know, feel free to comment it here..!!  :):):)

Letter Pattern

Write a program to print the following
         A
       B B
      CC CC
   DDD DDD





#include<stdio.h>
main()
{
      int i,j,n;
      printf("Enter Limit..  :  ");
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
      for(j=0;j<(n-i);j++)
      printf(" ");
      if(i==0)putchar(65);
      for(j=0;j<i;j++)putchar(65+i);      printf(" ");
        for(j=0;j<i;j++)putchar(65+i);
        printf("\n");
        }
        getch();
        }
     

C program to print a Number pattern

Write a program to print the following pattern:
0

1 1
2 3 5
8 13 21 34



Hi buddy, Jst analyse the no.s in order, 0,1,1,2,3,5,8,13,21,34....
Yess!!!! this is a Fibonacci series.

0+1=1
1+1=2
1+2=3
2+3=5... and so on

Next requirement is to generate pattern. First line has 1 element, second line has 2 elements and so on. And total number of elements in whole pattern will be N*(N+1)/2 , if there are N number of lines.





#include<stdio.h>
main()
{
      int n,i,j,k=0;
      int a[20];
      printf("Enter the lmit..:   ");
      scanf("%d",&n);
      a[0]=0;
      a[1]=1;
      for(i=2;(i<n*(n+1)/2);i++)
      a[i]=a[i-1]+a[i-2];
      for(j=0;j<=n;j++)
     {
      for(i=0;i<j;i++)
      printf("%d\t",a[k+i]);
      k+=i;
      printf("\n");
      }
      getch();
}

C program to Print a number table

Write a program to display the following format:
Nosum
11
23
36
410
515

Logic:

First column contains natural numbers serially..
second column contains  ( Current first column element+ previous second column element)
2+1=3
3+3=6
4+6=10
5+10=15




#include<stdio.h>
main()
{
      int j=0,z,i,n;
      printf("Enter the Limit...  :  ");
      scanf("%d",&n);
      printf("\n----------------\n
printf("no\tsum");
printf("\n------------------\n");
     
      for(i=1;i<=n;i++)
      {
      printf("\n%d",i);
      j+=i;
      printf("\t%d",j);
      }
      getch();
      }
     
     
     





Reverse words in a string using Recursion

Write a program to perform the following to any input string:
     
       Input : Structure is a derived datatype
      output: erutcurtS si a devired epytatad

My Code:

#include<stdio.h>
#include<string.h>
int main()
{
    char line[20],word[10];
    int i,j=0,len;
    printf("Entera string :  ");
    gets(line);
    len=strlen(line);
    for(i=0;i<len;i++)
    {
    while(line[i]!=' '&&i<len)
    word[j++]=line[i++];
    for(j--;j>=0;j--)
    printf("%c",word[j]);
    printf(" ");

    j=0;
    }
    getch();
    return 1;
}


I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!!  :):):)

C program to find Size of a structure without using sizeof() operator

Write a program to find the size of following structure without using size of operator

struct ABC
 {
 int a;
 float b;
 char c;
 };



Hai Viewer, confused?? Hmm.. calculating the size of a datatype without using sizeof() operator seems to be weird. But pointers will help you to solve this problem.  First u have to initialize a null pointer on intended datatype .You know that in 'structure ' separate memory will be allocated to each element. So, on incrementing that pointer variable, the value of that pointer will be incremented by size of that structure . That is our Goal..!!!! :)
Since we have initialized pointer with 0 we simply need to print the current pointer value..!!



solution

#include<stdio.h>
struct  ABC
{
    int a;

    float b;
    char c;
};
int main()
{

    struct ABC *ptr=(struct ABC *)0;
    ptr++;
printf("%d",ptr);
getch();
return 1;
}



I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!!  :):):)





C program to Print a Non-Fibonacci series

Write a C program to generate non-fibonacci series to given Limit:

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

main()
{
 int n,a,b,c,d,x;

 a=0;
 b=1;
 c=0;
 printf("Enter the upper range of the series:");
 scanf("%d",&n);

 while(c<=n)
 {
  c=a+b;
  a=b;
  b=c;
  d=a+b;

  for(x=c+1;x<d;x++)
  {
   if(x<=n)
    printf("%d",x);
   else
    break;
  }
 }
 getch();
}


I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!!  :):):)