0% found this document useful (0 votes)
8 views6 pages

C Programs for Basic Number Operations

The document contains four C programs that perform different tasks: determining if a number is even or odd, finding the first n prime numbers, calculating the sum of n numbers, and identifying the largest among n numbers. Each program includes user input prompts and outputs the results accordingly. The date of creation for the first two programs is 19/11/24, while the last two were created on 26/11/24.

Uploaded by

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

C Programs for Basic Number Operations

The document contains four C programs that perform different tasks: determining if a number is even or odd, finding the first n prime numbers, calculating the sum of n numbers, and identifying the largest among n numbers. Each program includes user input prompts and outputs the results accordingly. The date of creation for the first two programs is 19/11/24, while the last two were created on 26/11/24.

Uploaded by

rinkigaya1983
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. WAP to find even or odd number based on user input.

(Date: 19/11/24)

#include<stdio.h>

int main ()

printf("\n\n\t\t program to find even or odd number \n\n\n");

int n;

printf("Enter a number: ");

scanf("%d",&n);

if((n/2)*2 == n)

printf("\n\n\t\t %d is Even\n", n);

else

printf("\n\n\t\t %d is Odd\n", n);

printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");

return 0;

[Link] to find first n prime number. (date; 19/11/24)

#include<stdio.h>

int main()

{
printf("\n\n\t\t program to find first n prime numbers\n\n\n");

int n,i = 3, count, c;

printf("\nEnter the number of prime numbers required : ");

scanf("%d", &n);

if(n >= 1)

printf("\n\nFirst %d prime numbers are : ", n);

printf("2 ");

// iteration for n prime numbers

// i is the number to be checked in each iteration starting from 3

for (count = 2; count <= n; i++)

// iteration to check c is prime or not

for (c = 2; c < i; c++)

if(i%c == 0)

break;

if(c == i) // c is prime

printf("%d ", i);


count++; // increment the count of prime numbers

printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");

return 0;

Output :

[Link] to find sum of n numbers. (Date : 26/11/24)

#include<stdio.h>

int main()

printf("\n\n\t\t program to find sum of n numbers \n\n\n");


int n,sum=0,c,value;

printf("\n\nEnter the number of integers you want to add: ");

scanf("%d", &n);

printf("Enter %d integers\n\n",n);

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

scanf("%d", &value);

/*

need to initialize sum before using otherwise

garbage value will get printed

*/

sum += value;

printf("\n\n\nsum of entered numbers = %d", sum);

printf("\n\n\t\t\tCoding is Fun !\n\n\n");

return 0;

[Link] to find largest among N numbers.(Date ; 26/11/24)

#include<stdio.h>

int main()
{

printf("\n\n\t\t program to find largest among N numbers \n\n\n");

int n,i;

float c,big;

printf("\n\nEnter the number of elements you wish to find the greatest element of:
");

scanf("%d", &n);

printf("\n\nEnter %d numbers :\n", n);

printf("\n\n\t\t\tElement 1: ");

//Important step- always initialize big to the first element

scanf("%f", &big);

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

printf("\n\t\t\tElement %d : ", i);

scanf("%f", &c);

/*

if input number is larger than the

current largest number

*/

if(big < c)

big = c; // update big to the larger value

}
printf("\n\n\nThe largest of the %d numbers is %f ", n, big);

printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");

return 0;

Output :

You might also like