0% found this document useful (0 votes)
22 views8 pages

11.//WAP To Sum All The Numbers Till N Numbers

The document contains code snippets for several programs: 1) A program to calculate the sum of numbers from 1 to n. 2) A program to sort and count even and odd numbers in an array. 3) A program to print a pattern of asterisks in increasing rows. 4) Additional programs to calculate sums of factorials, squares, and squares of numbers with a specific digit.

Uploaded by

Rupinder Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

11.//WAP To Sum All The Numbers Till N Numbers

The document contains code snippets for several programs: 1) A program to calculate the sum of numbers from 1 to n. 2) A program to sort and count even and odd numbers in an array. 3) A program to print a pattern of asterisks in increasing rows. 4) Additional programs to calculate sums of factorials, squares, and squares of numbers with a specific digit.

Uploaded by

Rupinder Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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