Friday, August 24, 2012

Find numbers between 100 to 200 which divisible by 7 and calculate number sum

Q. Write a C program to find the numbers and their sum between 100 to 200 which are divisible by 7.

or


Q. Write a C program to accept two randomly number from user and find out the numbers and their sum which are divisible by user entered number.  

Ans.

/*c program for find the number between 100 to 200 which are divisible by 7 and also calculate these number sum*/

#include<stdio.h>
#include<conio.h>
int main()
{

 int n1,n2,div,sum=0;
 printf("Note: First number must be less then to second number\n\n");
 printf("Enter first number: ");
 scanf("%d", &n1);
 printf("Enter second number: ");
 scanf("%d", &n2);
 printf("Enter divisor: ");
 scanf("%d", &div);
 printf("Numbers that are divisor by %d :\n",div);
 for(n1; n1<=n2; n1++)
 {
  if(n1%div==0)
  {
    printf("%d\t",n1);
    sum=sum+n1;
  }
 }
 printf("\nSum of numbers that are divisible by %d = %d",div,sum);
 getch();
 return 0;
}


/************Output************/


Output of find the number between 100 to 200 which are  divisible by 7 and these numbers sum
Screen shot find the number between 100 to 200 which are
 divisible by 7 and  calculate its number sum C program

Search number is Fibonacci or not

Q. Write a C program to check number whether a number is Fibonacci term or not.

Ans.

/*c program to check a number is include in Fibonacci term or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int a,b,c,next,num;
 printf("Enter any number: ");
 scanf("%d", &num);
 if((num==0)||(num==1))
   printf("\n%d is a Fibonacci term",num);
 else
 {
   a=0;
   b=1;
   c=a+b;
   while(c<num)
   {
     a=b;
     b=c;
     c=a+b;
   }
   if(c==num)
     printf("\n%d is a Fibonacci term",num);
   else
     printf("\n%d is not a Fibonacci term",num);
 }
 getch();
 return 0;
}

/************Output************/

Output of number is Fibonacci term C program
Screen shot for number is Fibonacci term C program


Output of number is not a Fibonacci term C program
Screen shot for number is not comes
in Fibonacci term C program

Thursday, August 23, 2012

Fill the screen with Smiley Face Icon

Q. Write a C program to fill the display screen with smiley.
(C funny program)

Hint: ASCII value of Smiley Icon is 1.

Ans.

/*c program to fill all the screen to smiley icon*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int x,y;
 for(x=1, y=1; y<=1000; y++)
   printf("%2c",x);
 getch();
 return 0;
}

/************Output************/


Output of fill all screen to smiley icon C program
Screen shot for C funny program to
fill all screen with smiley 
Related Program:

  1. Print all ASCII table C program

Sunday, August 12, 2012

Reverse array

Q. Write a c program to accept n elements from user and reverse all elements.


Ans.

/*c program for reverse an array*/
#include<stdio.h>
#include<conio.h>
#define S 50
int main()
{
 int i,num,mid;
 float arr[S],tmp;
 printf("Ener total number of element in array : ");
 scanf("%d", &num);
 for(i=0; i<num; i++)
 {
   printf("Enter %d element : ",i+1);
   scanf("%f", &arr[i]);
 }
 mid = num/2;
 for(i=0; i<mid; i++)
 {
   /*swapping*/
   tmp = arr[i];
   arr[i]= arr[num-1-i];
   arr[num-1-i] = tmp;
 }
 printf("\n-- Array in reverse order --\n\n");
 for(i=0; i<num; i++)
    printf("\t%.2f\n",arr[i]);
 getch();
 return 0;
}

/************Output************/


Output of accept n elements from user and reverse all elements C program
Screen shot for reverse array C program

Related program:
  1. Reverse array using simple C program

Wednesday, August 8, 2012

Reverse number and check palindrome or not

Q. Write a C program to accept any number from user and reverse it. Also find it that number is palindrome or not.

for example:

number- 12345
result- 
        reverse:54321
        number is not palindrome

Ans.

/*c program for reverse a given number and check it for palindrome or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,rem,n,rev=0;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=num; n!=0; n=n/10)
 {
    rem = n%10;
    rev = rev*10+rem;
 }
 printf("\nEntered number in reverse order: %d\n",rev);
 if(rev==num)
    printf("%d is Palindrome.", num);
 else
    printf("%d is not Palindrome.", num);
 getch();
 return 0;
}

/************Output************/

Output of reverse number and number is not palindrome C program
Screen shot for reverse number and number
 is not palindrome C program

Output of reverse number and number is palindrome C program
Screen shot for reverse number and number
 is palindrome C program

Split string vertically only words not characters

Q. Write a C program to print the string vertically only words not all characters.

For example:

string: You are genius to learn C language
result:
     You
     are
     genius
     to
     learn
     C
     Language

Ans.

/*c program to print string vertically only words not characters*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i;
 char str[30];
 printf("Enter any string: ");
 gets(str);
 for(i=0; str[i]!='\0'; i++)
 {
  if(str[i]==' ')
     printf("\n");
  else
     printf("%c",str[i]);
 }
 getch();
 return 0;
}

/***********Output***********/

Output of print string vertical only words not characters C program
Screen shot for print string vertical only
words not characters C program

Tuesday, August 7, 2012

Print prime number 1 to 100

Q. Write a C program to accept a specific last number and print all the less then or equal prime number.
or
Q. Write a C program to print the prime number between 1 to n number.
for example: 1 to 100

Ans.

Note:-
1. 1 is not the prime number.
2. All even number is not the prime number except the number 2.

/*C program to print 1 to 100 prime numbers*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,n,div,p;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=2; n<=num; n++)
 {
  for(div=2; div<n; div++)
  {
   if(n%div==0)
   {
     p=0;
     break;
   }
   p=1;
  }
  if(p)
    printf("\t%d",n);
 }
 getch();
 return 0;
}

/************Output************/


Output of print 1 to 100 prime number C program
Screen shot for print the prime number
between 1 to 100 C program

Related program:

  1. Generate first n prime number C program
  2. Search for prime number C program
  3. Flowchart for search prime number

Generate first n Prime number

Q. Write a C program to generate first n prime number C program.

Ans.

/*c program for generate first n prime number*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int n,num,t,div,count;
 printf("How many prime number you want to print: ");
 scanf("%d", &n);
 printf("\n%d\t",2); /*2 is first prime number*/
 count=1;
 num=3;
 while(count<n)
 {
  t=sqrt(num);
  div=2;
  while(div<=t)
  {
    if(num%div==0)
       break;
    div++;
  }
  if(div>t)
  {
     printf("%d\t",num);
     count++;
  }
  num=num+2;
 }
 getch();
 return 0;
}

/************Output************/


Output of generate first n prime number C program
Screen shot for generate first n prime number
C program

Related Programs:

  1. Print Prime Number 1 to 100 C program
  2. Search for Prime Number C program
  3. Flowchart for search prime number

Sunday, August 5, 2012

String vertical using pointer

Q. Write a C program to accept a string and print its in vertical order using pointer.


Ans.


/*c program to print string vertically using pointer*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 char *p;
 printf("Enter any string: ");
 gets(str);
 printf("String in vertical order as:\n\n");
 for(p=str; *p!='\0'; p++)
   printf("%8c\n",*p);
 getch();
 return 0;
}


/************Output************/


Output of display string vertically using pointer C program
Screen shot for print string vertically
using pointer C program

Saturday, August 4, 2012

Reverse all words and string using pointer

Q. Write a C program to accept a string from user and reverse all words with string using pointer.


for example:


string: This Is A Good Blog
result: golB dooG A sI sihT


Ans.

/*c program for accept string and print it all words with string in reverse order using pointer*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 char *p;
 printf("Enter any string: ");
 gets(str);
 printf("\n-- Reversing string with words & character --\n\n");
 for(p=str; *p!='\0'; p++);
 for(p--; p>=str; p--)
    printf("%c",*p);
 getch();
 return 0;
}


/************Output************/


Output of reverse all words and string using pointer C program
Screen shot for reverse all words and string
using pointer C program

Series addition

Q. Write a C program to add the following series and print the result of addition:


(1/1!) + (2/2!) + (3/3!) + (4/4!) + (5/5!)


Ans.


/*c program to add the given series and print the result of its addition*/
#include<stdio.h>
#include<conio.h>
int main()
{
 float num,c,tmp,fact,res=0;
 for(num=1; num<=5; num++)
 {
  for(tmp=1, fact=1; tmp<=num; tmp++)
  {
    fact = fact*tmp;
    c = num/fact;
  }
  res=res+c;
 }
 printf("Result of series addition: \n");
 printf("\n(1/1!) + (2/2!) + (3/3!) + (4/4!) + (5/5!) = %f",res);
 getch();
 return 0;
}


/************Output************/
Output of add the specific given series C program
Screen shot for add the given series C program

Friday, August 3, 2012

Generate Fibonacci series using recursion

Q. Write a C program to generate Fibonacci series using recursion method.
or
Q. Write a C program to accept any number from user and create its equal-ant Fibonacci series using recursion method.

Ans.

/*c program to generate Fibonacci series using recursion method*/
#include<stdio.h>
#include<conio.h>
int fibo(int , int ); /*declaration function*/
int main()
{
 int num=1,previous_num=0;
 printf("Fibonacci Series first 30 elements: ");
 printf("\n\n\t1");
 fibo(previous_num,num); /*calling function*/
 getch();
 return 0;
}

fibo(int prev, int n) /*definition of function*/
{
 static int r=1;
 int series;
 if(r!=30)
 {
   series=prev+n;
   prev=n;
   n=series;
   printf("\n\t%d",series);
   r++;
   fibo(prev,n);
 }
}

/************Output************/


Output of generate Fibonacci series to specific number using recursion method C program
Figure: Screen shot for Generate Fibonacci series to a 
specific range using recursion method C program



Related Programs:
  1. Fibonacci series C program
  2. Flowchart for Fibonacci series
  3. Search a number is Fibonacci term or not

Thursday, August 2, 2012

Print ASCII table

Q. Write a C program to print the ASCII table with numbers and corresponding characters.
or
Q. Write a C program to print the ASCII values 0 to 255 with numbers and related value.

Ans.

/*c program to print all ASCII table and its equivalent values with numbering*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i;
 printf("ASCII table & its equivalent values with numbering: \n");
 for(i=1; i<=255; i++)
   printf("\nValue: %d -> ASCII character: %c",i,i);
 getch();
 return 0;
}

/************Output************/
/*Six snap shot for ASCII values: 0 to 255*/


Output of ASCII code value from 1 to 41
Screen shot for ASCII table 1 to 41


Output of ASCII code value from 42 to 86
Screen shot for ASCII table 42 to 86 

Output of ASCII code value from 87 to 131
Screen shot for ASCII table 87 to 131

Output of ASCII code value from 132 to 176
Screen shot for ASCII table 132 to 176

Output of ASCII code value from 177 to 221
Screen shot for ASCII table 177 to 221

Output of ASCII code value from 222 to 255
Screen shot for ASCII table 222 to 255

Related Program:

  1. Fill the screen with smile face icon. ( ASCII value of 'smile face' is '1' )

Reverse all words but not string using pointer

Q. Write a C program to accept a string from user and reverse all words but not string using pointer.


For example:


String: This Is A Good Blog
Result: sihT sI A dooG golB


Ans.

/*c program for reverse all words but not string using pointer*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 char *p,*tmp;
 printf("Enter any string: ");
 gets(str);
 for(p=str; *p!='\0'; p++)
 {
  if(*(p+1)==' ' || *(p+1)=='\0')
  {
   for(tmp=p; *tmp!=' ' && tmp>=str; tmp--)
     printf("%c",*tmp);
  }
  printf(" ");
 }
 getch();
 return 0;
}


/************Output************/


Output of reverse all words but not string using pointer C program
Screen shot for reverse all words in string but string in same order C program

Calculate Factorial value using recursion

Q. Write a C program to accept any number from user and calculate its factorial value using recursion method.


Ans.


/*c program to find out factorial value using recursion method*/
#include<stdio.h>
#include<conio.h>
int fact(int );
int main()
{
  int num,res;
  printf("Enter any number: ");
  scanf("%d", &num);
  res = fact(num);
  printf("Factorial value is: %d",res);
  getch();
  return 0;
}
int fact(int n)
{
  int f;
  if(n==1)
     return(1);
  else
     f = n*fact(n-1);
  return(f);
}


/************Output************/


Output of calculate factorial value using recursion method C program
Screen shot for calculate factorial value using recursion method