List of C Programs that makes u understand concepts in an easy fashion(Part1)

A very Good Day to all my Readers, Today i received a Query Regarding solutions towards common C programs, using which one can understand the concepts of C in easy Way. So here is a complete Ready To Use Solution Kit for you reader


Program 1 Program to print A to Z along with equivalent ASCII Value

main()
{

int ch,c;
clrscr();
c=1;
ch=65;
printf("Alphabet\t\t ASCII Value\n");
while(c<=26)
{
printf("%c",ch);
printf("\t\t%d",ch);
printf("\n");

ch=ch+1;
c=c+1;
}
getch();
}

Program 2 : Write C program to calculate Factorial of given Number

main()
{
int fact,num;
clrscr();

printf("Enter Any Number:");
scanf("%d",&num);

fact=1;

while(num>=1)
{
fact=fact*num;
num=num-1;
}

printf("Factorial is %d",fact);
getch();
}


Program 3 Program to calculate Sum of first n natural numbers

#include <stdio.h>

main()
{
int n,t,sum;
clrscr();

printf("How Many natural Number:");
scanf("%d",&n);

sum=0;
t=0;

while(t<=n)
{
sum=sum+1;
t=t+1;
}

printf("Sum of %d natural Numbers is %d",n,sum);
getch();
}

Program 4 Program to Generate following pattern 1    4  9 16 ... 100

main()
{
int n,p;
clrscr();
n=1;
p=1;

while(n<=10)
{
p=n*n;
n=n+1;
printf("    %d",p);
}
getch();

}

Program 5: Program to Generate Following pattern

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

main()
{
int n,c,p;
clrscr();

n=1;c=1;p=1;

while(c<=5)
{
while(n<=c)
{
printf("   %d",n);
n=n+1;
}

n=n-2;

while(n>=1)
{
printf("  %d",n);
n=n-1;
}

c=c+1;
n=1;
                 printf("\n");
}
}

Program 6: Program to generate following given pattern
5
5 4
5 4 3
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
main()
{
int n,c,p;
clrscr();
c=1;
while(c<=5)
{
p=5;
n=1;

while(n<=c)
{
printf("%d",p);
p=p-1;
n=n+1;
}
c=c+1;
                printf("\n");
}

c=c-2;
while(c>=1)
{
p=5;
n=1;

while(n<=c)
{
printf("  %d",p);
p=p-1;
n=n+1;
}
c=c-1;
                printf("\n");
}
getch();

}

Program 7: Program to calculate nP i.e. n to the power P

main()
{
int n,m,p;

clrscr();

printf("Enter Number:");
scanf("%d",&n);


printf("Enter POwer");
scanf("%d",&p);

m=1;

while(p>=1)
{
m=m*n;
p=p-1;
}

printf("Answer is :%d",m);
getch();

}



Program 8 Program to perform Decimal to Binary COnversion Program

main()
{
int num,q,r;

clrscr();

printf("Enter Number:");
scanf("%d",&num);


while(1)
{

q=num/2;
r=num%2;

if(q<1)
{
printf("%d",r);
break;
}
printf("%d",r);

num=q;
}
getch();
}

Continue Reading Second Part for More Solutions

Comments

Popular posts from this blog

Understanding Working of Text & Binary File in C

Starting C : A series of Chapters to learn C