Professional Documents
Culture Documents
h>
int main() {
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
2.#include <stdio.h>
int main() {
int rows, i, j, number = 1;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; ++j) {
printf("%d ", number);
++number;
}
printf("\n");
}
return 0;
1
2 3
4 5 6
7 8 9 10
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,result=0;//variable declaration
// from the user - input from keyboard
printf("Enter two number for input: ");
scanf("%d %d",&num1,&num2);//Reading the input for num1 and num2
while(num1>=num2) {
num1=num1-num2;
result++;
}
printf("Division is: %d",result);
getch();
return 0;
}
1. #include<stdio.h>
2. int main()
3. {
4. int a=10, b=20;
5. printf("Before swap a=%d b=%d",a,b);
6. a=a+b;//a=30 (10+20)
7. b=a-b;//b=10 (30-20)
8. a=a-b;//a=20 (30-10)
9. printf("\nAfter swap a=%d b=%d",a,b);
10. return 0;
11. }
#include <stdio.h>
int i, j;
arr[j] = arr[j+1];
arr[j+1] = temp;
int main()
int n,i;
scanf("%d",&n);
int arr[n];
scanf("%d",&arr[i]);
sort(arr, n);
return 0;
#include<stdio.h>
#include<conio.h>
void main()
{
int i,arr[20],j,no;
clrscr();
printf("Enter size of array: ");
scanf("%d",&no);
printf("Enter any %d elements in array: ",no);
for(i=0;i<no;i++)
{
scanf("%d",&arr[i]);
}
printf("Duplicate elements are: ");
for(i=0; i<no; i++)
{
for(j=i+1;j<no;j++)
{
if(arr[i]==arr[j])
{
printf("%d\n",arr[i]);
}
}
}
getch();
}
int main()
{
int n;
scanf(“%d”,&n);
for(int i=n+1;i>0;i++)
{
int count=0;
for(int j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2){
printf(“%d”,i);
break;
}
}
10.ANAGRAM PROGRAM
#include <stdio.h>
#include <string.h>
char temp;
int i, j;
int n = strlen(s1);
int n1 = strlen(s2);
if( n != n1) {
printf("%s and %s are not anagrams! \n", s1, s2);
return 0;
}