Wednesday, 18 March 2015

C Programs For Engineering 1st year Students page 2



Page 2

11. Program to print natural numbers from 1 to 10 in Reverse

#  include <stdio.h>
#  include <conio.h>
 main( )
{
int i;
clrscr( );
for (i=10; i>=1; i--)
printf(“%d\n”,i);
getch( );
}

12. Program to print sum of the natural numbers from 1 to 10.

#  include <stdio.h>
#  include <conio.h>
 main( )
{
int n,sum=0,i;
clrscr( );
for (i=1; i<=10; i++)
sum=sum+i;
printf(“sum of natural numbers from 1 to 10 is %d\n”,sum);
getch( );
}

13. Program to accept a number and print mathematical table of the given no.

#  include <stdio.h>
#  include <conio.h>
 main( )
{
int i,t;
clrscr( );
printf(“which table u want:”);
scanf(“%d”,&t);
for (i=1; i<=10; i++)
printf(“\n%d*%d=%d”,t,i,i*t);
getch( );
}

14. Program to print 1 to 10 mathematical tables .

#  include <stdio.h>
#  include <conio.h>
 main( )
{
int i,j;
clrscr( );
for (i=1; i<=10; i++)
for(j=1;j<=10;j++)
printf(“\n%d*%d=%d”,i,j,i*j);
getch( );
}

15. Program to print fibonacci series .

#  include <stdio.h>
#  include <conio.h>
main( )
{
int a=0,b=1,c=0,i;
clrscr( );
printf(“%d”,a);
printf(“\n%d”,b);
for (i=1; i<=10; i++)//(n-2)
{
c=a+b;
printf(“\n%d”,c);
a=b;
b=c;
}
getch( );
}

16. Program to print numeric pyramid

#  include <stdio.h>
#  include <conio.h>
main()
{
int  i,j;
clrscr( );
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf(“%d”,j);
printf(“\n”);
}
getch();
}
17. Program to print numerical pyramid.

#  include <stdio.h>
#  include <conio.h>
main( )
{
int i,j ,l,k=40;
clrscr( );
for(i=1;i<=9;i+=2)
{
for(l=1;l<=k;l++)
printf(“    “ );
for(j=1;j<=i;j++);
printf(“%d”,j);
printf(“\n”);
k=k-2;
}
getch( );
}

18. Program to print numerical  diamond.

#  include <stdio.h>
#  include <conio.h>
main( )
{
int i,j,l,n,s,k=40;
clrscr( );
for(i=1;i<=9;i+=2)
{
for(l=1;l<=k;l++)
printf(“    “);
for(j=1;j<=i;j++)
printf(“\n”);
k=k-2;
}
k=k+4;
for(n=7;n>=1;n-=2)
{
for(i=1;i<=k;i++)
printf(“   “);
for(s=1;s<n;s++)
printf(“%d”,s);
printf(“\n”);
k=k+2;
}
getch( );
}

19. Program to print character pyramid.

#  include <stdio.h>
#  include <conio.h>
main( )
{
char i,j;
clrscr();
for(i=65;i<=70;i++)
{
for(j=65;j<=i;j++)
printf(“%c”,j);
printf(“\n”);
}
getch( );
}

20. Program to print character diamond.

#  include <stdio.h>
#  include <conio.h>
main( )
{
char i,j,n,r;
int s,sp=40;
clrscr( );
for(i=65;i<=75;i+=2)
{
for(s=1;s<=sp;s++)
printf(“     “);
for(j=65;j<i;j++)
printf(“%c”,j);
printf(“\n”);
sp=sp-2;
}
sp=sp+4;
for(n=73;n>=65;n-=2)
{
for(s=1;s<=sp;s++)
printf(“   “);
for(r=65;r<=n;r++)
printf(“%c”,r);
sp=sp+2;
}
getch( );
}




Pages 1, 2345678910

0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Text Widget

Blog Archive