Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

11.//WAP to sum all the numbers till n numbers.

#include<conio.h>

#include<stdio.h>

void main()

int n,j,sum=0;

printf("Enter the Number : ");

scanf("%d",&n);

for(j=1;j<=n;j++)

printf("%d ",j);

sum=sum+j;

printf("\nSum of %d is : %d ",n,sum);

getch();

}
12.//WAP to sort and count even and odd number in the array.
#include<stdio.h>

#include<conio.h>

void main()

int ar[100],i,n;

printf("Enter the size of the array \n");

scanf("%d",&n);

printf("Enter the elements of the array \n");

for(i=0; i<n; i++)

scanf("%d",&ar[i]);

printf("Even numbers in the array are - ");

for(i=0;i<n;i++)

if(ar[i]%2==0)

printf("%d \t",ar[i]);

printf("\n Odd numbers in the array are - ");

for(i=0;i<n;i++)

if(ar[i]%2!=0)

{
printf("%d \t",ar[i]);

getch();

}
13.//WAP to create a pattern.
#include<stdio.h>

#include<conio.h>

void main()

int i,j;

for(i=1;i<=6;i++)

for(j=1;j<=i;j++)

printf("*");

printf("\n");

getch();

}
14.//WAP to find sum of 1/factorial till numbers.
#include<conio.h>

#include<stdio.h>

void main()

int n,i,fact=1;

float sq,sum=0;

printf("Enter any no.");

scanf("%d",&n);

for(i=1;i<=n;i++)

fact=fact*i;

printf("%d\n",fact);

sq=1/fact;

sum=sum+sq;

printf("sum of 1/factorial is %f",sum);

getch();

}
15.//WAP to calculate sum of squares of numbers till n
numbers.
#include<conio.h>

#include<stdio.h>

void main()

int n,i,sum=0,sq;

printf("Enter any no:-");

scanf("%d",&n);

for(i=1;i<=n;

i++)

sq=i*i;

sum=sum+sq;

printf("Sum of square of %d nos is;- %d",n,sum);

getch();

}
16.//WAP to print the square of numbers whose least
significant digit is 5 till n.
#include<stdio.h>

#include<conio.h>

void main()

int n,i,sq;

printf("Enter a number");

scanf("%d",&n);

if(n%5==0)

for(i=5;i<=n;i+=10)

sq=i*i;

printf("The result is%d",sq);

else

printf("Error input");

getch();

You might also like