Programs:
Write a C
program to find the factorial of N numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, f=1,n;
clrscr();
printf(“\n enter any number”);
scanf(“%d”, &n);
for(i=1; i<=n; i++)
{
f=f*i;
}
printf(“Factorial of given number is %d”,f);
getch();
}
Output:
enter any
number
5
5
Factorial of given number is 120
Write a C
program to print the following triangle of numbers.
1
12
123
1234
12345
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf(“%d”, j);
}
printf(“\n”);
}
getch();
}
Output:
1
12
123
1234
12345
Write a C
program to print the following triangle of numbers.
55555
4444
333
22
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for(i=5; i>=1; i--)
{
for(j=i; j>=1; j--)
{
printf(“%d”, i);
}
}
printf(“\n”);
}
getch();
}
Output:
55555
4444
333
22
Write a C
program to print the following triangle.
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf(“ * “, j);
}
printf(“\n”);
}
getch();
}
Output:
*
* *
* * *
* * * *
* * * * *
Write a C
program to print the following triangle of numbers.
54321
4321
321
21
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=5; i>=1; i--)
{
for(j=i; j>=1; j--)
{
printf(“%d”, j);
printf(“\n”);
}
}
getch();
}
Output:
54321
4321
321
21
1
Write a C
program to print the following triangle of numbers.
1
22
333
4444
55555
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf(“%d”, i);
}
printf(“\n”);
}
getch();
}
Output:
1
22
333
4444
55555
Write a C
program to print the following triangle of numbers.
1
2 3
4 5 6
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, k=1;
clrscr();
for(i=1; i<=4; i++)
{
printf(“\n”);
for(j=1; j<=i; j++)
{
printf(“%d”, k);
k++;
}
}
getch();
}
Output:
1
2 3
4 5 6
7 8 9 10
Write a C
program to print the following pyramid of numbers.
1
2
3
4
5 6
7
8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j, k=1, l;
clrscr();
for(i=1; i<=4; i++)
{
for(l=4; l>=i; l--)
{
printf(“ “);
for(j=1; j<=i; j++)
{
printf(“%d”, k);
k++;
}
printf(“\n”);
}
getch();
}
Output:
1
2
3
4
5 6
7
8 9 10
Write a C
program to find even number using while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, a=0;
clrscr();
while(n!=99)
{
printf(“\n enter number”);
scanf(“%d”, &n);
if(n%2==0)
a=a+1;
}
printf(“Even Number=%d”, a);
getch();
}
Output:
enter number
6
Even
Number=6
Write a C
program to input name and age and print the same.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
char name[10], ch;
clrscr();
while(ch!=’n’)
{
printf(“\n enter name and age”);
scanf(“%s%d”, &name,
&age);
printf(“\n Name=%s”, name);
printf(“\n Age=%d”, age);
printf(“\n do you want to
continue”);
scanf(“%c”, ch);
}
getch();
}
Some other links:
No comments:
Post a Comment