Thursday, November 26, 2009

Write a C program to print the given alphabet pyramid -2


A B C D E F G F E D C B A
A B C D E F E D C B A
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A


#include<stdio.h>
#incldue<conio.h>
int main( )
{
int r,c,askey,sp;
clrscr( );

for( r=7; r>=1; r-- )
{
for(sp=6; sp>=r; sp--)
printf(" "); //2 spaces

askey=65;
for(c=1; c<=r; c++ )
printf("%2c", askey++ );

for(c=r-1; c>=1; c-- )
printf("%2c", --askey);

printf("\n");
}
getch();
return 0;
}

Output:-
A B C D E F G F E D C B A
A B C D E F E D C B A
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A

Write a C program to print the given alphabet pyramid.

A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
-----------------------------------

#include<stdio.h>
#include<conio.h>
int main( )
{
int r,c,askey;
clrscr( );

for( r=7; r>=1; r-- )
{
askey=65;
for(c=1; c<=r; c++ )
printf("%2c", askey++ );
    askey--; 
    for(c=r; c>=1; c-- )
printf("%2c", askey--);

printf("\n");
}
getch();
return 0;
}

Output:-
A B C D E F G G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A

Note:- 
'r' and 'c' means rows and columns .
'askey' variable is for disp. values.

Friday, November 20, 2009

C question and answer with explanation









31. SUM OF SQUARES OF THE SERIES 12+22+32+--------+n2
void main()
{
long int r;
clrscr();
printf("\nEnter the range: ");
scanf("%ld",&r);
printf("\nSum of the squares of the series is: %ld",((r*(r+1))*(2*r+1))/6);
getch();
}
32. SUM OF CUBES OF THE SERIES 13+23+33+---------+n3
void main()
{
int r;
clrscr();
printf("\nEnter the number range: ");
scanf("%d",&r);
printf

C questions and answer with explanation




1. PERFECT NUMBER.
void main()
{
int n,i=1,sum=0;
clrscr();
printf("\nEnter a number:-");
scanf("%d",&n);
while(i {
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("\nThe no %d is a perfect number",i);
else
printf("\nThe no %d is not a perfect number",i);
getch();
}
2. ARMSTRONG NUMBER.
void main()
{
int

C question and answer




16. PRINTING ASCII VALUE
void main()
{
int i;
clrscr();
for(i=0;i<=255;i++)
{
printf("%d -> %c ",i,i);
delay(10);
}
getch();
}
17. CHECKING LEAP YEAR
void main()
{
int year;
clrscr();
printf("Enter any year->");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf

C questions with answer

Variable naming rule in c programming language:
(q) What will be output of the following program?
void main()
{
char * emp name=�raja�;
printf("%s",emp name);
getch();
}
Output: Compilation error
Explanation:
Error: Invalid variable name. Except underscore there should not be any special character in name of variable event blank space.
(q) What will be output of the following program?
void main()

C questions and answer








(51) What will be output if you will compile and execute the following c code?

struct marks{
int p:3;
int c:3;
int m:2;
};
void main(){
struct marks s={2,-6,5};
printf("%d %d %d",s.p,s.c,s.m);
}

(a) 2 -6 5
(b) 2 -6 1
(c) 2 2 1
(d) Compiler error
(e) None of these






Answer: (c)