0% found this document useful (0 votes)
12 views25 pages

Anas Khan

This document is an assignment for a computer programming course submitted by Anas Khan. It includes a comprehensive index of various C programming exercises, covering topics such as basic input/output, arithmetic operations, control structures, and functions. Each program is listed with its corresponding page number and includes code snippets demonstrating its functionality.

Uploaded by

Jatin Sharma
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)
12 views25 pages

Anas Khan

This document is an assignment for a computer programming course submitted by Anas Khan. It includes a comprehensive index of various C programming exercises, covering topics such as basic input/output, arithmetic operations, control structures, and functions. Each program is listed with its corresponding page number and includes code snippets demonstrating its functionality.

Uploaded by

Jatin Sharma
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
You are on page 1/ 25

SESSION 2023-24

COMPUTER PROGRAMMING
ASSIGNMENT

SUBMITTED BY:- SUBMITTED TO:-


ANAS KHAN ANJALI DHAKAD
COMPUTER SCIENCE
ROLL NO.=23105C04004
SIGNATURE:……………
INDEX
# PROGRAM Page REMARKS/
no. SIGNATURE
1 Hello World Program 1

2 Program to Print Your Own Name 1


3 Program to Print an Integer Entered By the User 1
4 Program to Add Two Numbers 2

5 Program to Check Whether a Number is Prime or Not 2

6 Program to Multiply two Floating-Point Numbers 3

7 Program to Print the ASCII Value of a Character 3

8 Program to Swap Two Numbers 3

9 Program to Calculate Fahrenheit to Celsius 4

10 Program to Find the Size of int, float, double, and char 4

11 Program to Add Two Complex Numbers 4

12 Program to Print Prime Numbers From 1 to N 5

13 Program to Find Simple Interest 5

14 Program to Find Compound Interest 6


15 Program for Area And Perimeter Of Rectangle 6
16 Program to Check Whether a Number is Positive, Negative, or Zero 7

17 Program to Check Whether Number is Even or Odd 7


18 Program to Check Whether a Character is Vowel or Consonant 8

19 Program to Find Largest Number Among Three Numbers 8

20 Program to Calculate Sum of Natural Numbers 9

21 Program to Print Alphabets From A to Z Using Loop 9

22 Program to Check Leap Year 10

23 Program to Find Factorial of a Number 10

24 Program to Make a Simple Calculator 11

25 Program to Generate Multiplication Table 11

26 Program to Print Fibonacci Series 12

27 Program to Find LCM of Two Numbers 12

28 Program to Check Armstrong Number 13

29 Program to Display Armstrong Numbers Between 1 to 100 13

30 Program to Display Armstrong Number Between Two Intervals 14

31 Program to Reverse a Number 14

32 Program to Check Whether a Number is a Palindrome or Not 15

33 Program to Display Prime Numbers Between Intervals 15

34 Program to Check whether the input number is a Neon Number 16

35 Program to Find All Factors of a Natural Number 16

36 Program to Print Simple Pyramid Pattern 17

37 Program to Print Given Triangle 17

38 Program to Print 1800 Rotation of Simple Pyramid 18

39 Program to Print Inverted Pyramid 18

40 Program to Print Number Pattern 19

41 Program to Print Character Pattern 19

42 Program to Print Continuous Character Pattern 20

43 Program to Print Pascal’s Pattern Triangle Pyramid 21

44 Program to Display Prime Numbers Between Two Intervals Using Functions 22

45 Program to Find All Roots of a Quadratic Equation 23


C PROGRAMS ASSIGNMENT
1. C Hello World Program?
#include <stdio.h>
int main(){
printf("hello world")
return 0;
}

2. C Program to Print Your Own Name ?


#include <stdio.h>
int main(){
printf("Ankit Dhakad");
return 0;
}

3. C Program to Print an Integer Entered By the User?


#include<stdio.h>
int main(){
int n;
printf("enter any integer value:");
scanf("%d",&n);
printf("%d",n);
return 0;
}
4. C Program to Add Two Numbers?
#include<stdio.h>
int main(){
int a,b,sum;
printf("enter value of a:");
scanf("%d",&a);
printf("enter value of b:");
scanf("%d",&b);
sum=(a+b);
printf("the sum is:%d",sum);
return 0;
}

5. C Program to Check Whether a Number is Prime or Not?


#include<stdio.h>
int main(){
int n,i,count=0;
printf("enter any integer value:");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0){
count++;
}
}
if(count==2){
printf("number is prime");
}
else{
printf("number is not prime");
}
return 0;
}
6. C Program to Multiply two Floating-Point Numbers ?
#include <stdio.h>
int main(){
double a,b,product;
printf("Enter two numbers:");
scanf("%lf %lf",&a,&b);
product = a*b;
printf("the product is:%.2lf",product);
return 0;
}

7. C Program to Print the ASCII Value of a Character?


#include<stdio.h>
int main(){
char i;
printf("enter any character:");
scanf("%c",&i);
printf("%d",i);
return 0;
}

8. C Program to Swap Two Numbers?


#include<stdio.h>
int main(){
int a,b;
printf("enter value of a and b:");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("%d %d",a,b);
return 0;
}
9. C Program to Calculate Fahrenheit to Celsius?
#include<stdio.h>
int main(){
float fahrenheit , temp_in_celsius;
printf("enter temp in fahrenheit:");
scanf("%f",&fahrenheit);
temp_in_celsius=(fahrenheit-32)*5/9;
printf("temperature in celius is %f:",temp_in_celsius);
return 0;
}

10.C Program to Find the Size of int, float, double, and char?
#include <stdio.h>
int main(){
int a;
float b;
double c;
char d;
printf("the size is:%zu byte \n", sizeof(a));
printf("the size is:%zu byte \n", sizeof(b));
printf("the size is:%zu byte \n", sizeof(c));
printf("the size is:%zu byte \n", sizeof(d));
return 0;
}

11.C Program to Add Two Complex Numbers ?


#include <stdio.h>
int main() {
float real1, imag1, real2, imag2, realSum, imagSum;
printf("Enter the real part and imaginary part of the first complex number: ");
scanf("%f %f", &real1, &imag1);
printf("Enter the real part and imaginary part of the second complex number: ");
scanf("%f %f", &real2, &imag2);
realSum = real1 + real2;
imagSum = imag1 + imag2;
printf("The sum of the complex numbers is: %.2f + %.2fi\n", realSum, imagSum);
return 0;
}
12. C Program to Print Prime Numbers From 1 to N ?
#include<stdio.h>
int main(){
int n1, n2,i,j;
printf("enter range:");
scanf("%d %d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;

}
if (i==j)
printf("%d \t ",j);
}
return 0;
}

13. C Program to Find Simple Interest?


#include<stdio.h>
int main(){
int principal, rate, time,interest;
printf("enter principal amount:");
scanf("%d",&principal);
printf("Enter rate of interest:");
scanf("%d",&rate);
printf("Enter time period:");
scanf("%d",&time);
interest=(principal*rate*time/100);
printf("your interest is :%d",interest);
return 0;
}
14. C Program to Find Compound Interest?
#include<stdio.h>
int main(){
double principal, rate, time,amount,compound_interest;
printf("enter principal amount:");
scanf("%lf",&principal);
printf("Enter rate of interest:");
scanf("%lf",&rate);
printf("Enter time period:");
scanf("%lf",&time);
amount=principal*((pow((1+rate/100),time)));
compound_interest=amount-principal;
printf("Compound interest is :%lf",compound_interest);
return 0;
}

15. C Program for Area And Perimeter Of Rectangle?


#include<stdio.h>
int main(){
int length, breadth, perimeter , area ;
printf("Enter length:");
scanf("%d",&length);
printf("Enter breadth:");
scanf("%d",&breadth);
perimeter=2*(length+breadth);
area =(length*breadth);
printf("The perimeter is:%d \n",perimeter);
printf("The area is: %d",area);
return 0;
}
16. C Program to Check Whether a Number is Positive, Negative, or Zero?
#include<stdio.h>
int main()
{
float a;
printf("Enter any value:");
scanf("%f",&a);
if(a>0)
{
printf("number is positive\n");
}
else if(a<0)
{
printf("number is negative\n");
}
else
{
printf("number is zero\n");
}
return 0;
}

17. C Program to Check Whether Number is Even or Odd?


#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);

if (number % 2 == 0) {
printf("The number %d is even.\n", number);
} else {
printf("The number %d is odd.\n", number);
}

return 0;
}
18. C Program to Check Whether a Character is Vowel or Consonant ?
#include <stdio.h>
int main(){
char n;
printf("enter a character value :");
scanf("%c",&n);
if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u'||n=='A'||n=='E'||n=='I'||n=='O'||n=='U'){
printf("character is vowel");
}else
{
printf("character is consonant");
}
return 0;
}

19. C Program to Find Largest Number Among Three Numbers?


#include <stdio.h>
int main() {
float num1, num2, num3;
printf("Enter three numbers:\n");
scanf("%f %f %f", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3) {
printf("The largest number is: %.2f\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("The largest number is: %.2f\n", num2);
} else {
printf("The largest number is: %.2f\n", num3);
}

return 0;
}
20. C Program to Calculate Sum of Natural Numbers ?
#include <stdio.h>
int main() {
int n, sum;
printf("Enter a positive integer: ");
scanf("%d", &n);
sum = n * (n + 1) / 2;
printf("The sum of the first %d natural numbers is: %d\n", n, sum);

return 0;
}

21. C Program to Print Alphabets From A to Z Using Loop?


#include <stdio.h>
int main() {
char ch;
for (ch = 'A'; ch <= 'Z'; ch++) {
printf("%c\t", ch);
}
return 0;
}
22. C Program to Check Leap Year?
#include<stdio.h>
int main(){
int year;
printf("Enter the year :");
scanf("%d",&year);
if(year%400==0) {
printf("Entered year is a leap year");
}
else if (year%100==0) {
printf("Entered year is a leap year");
}
else if(year%4==0) {
printf("Entered year is a leap year");
}
else{
printf("Entered year is not a leap year");
}
return 0;
}

23. C Program to Find Factorial of a Number?


#include <stdio.h>
int main() {
int n, i;
unsigned long long factorial = 1;
printf("Enter a number: ");
scanf("%d", &n);
if (n < 0) {
printf("Factorial of a negative number doesn't exist.\n");
} else {
for (i = 1; i <= n; i++) {
factorial *= i;
}
printf("Factorial of %d = %llu\n", n, factorial);
}
return 0;
}
24. C Program to Make a Simple Calculator ?
#include<stdio.h>
int main(){
float a, b, c;
char ch;
printf("enter first number:");
scanf("%f",&a);
printf("enter user choice for operation (+,-,*,/):");
scanf(" %c" ,&ch);
printf("enter second number:");
scanf("%f", &b);
switch(ch) {
case'+':c=a+b;
printf("output=%.2f",c);
break;
case'-':c=a-b;
printf("output=%.2f",c);
break;
case'*':c=a*b;
printf("output=%.2f",c);
break;
case'/':c=a/b;
printf("output=%.2f",c);
break;
default:
printf("invalid operation .");
break;
}
return 0;
}

25. C Program to Generate Multiplication Table ?


#include <stdio.h>
int main() {
int num, i;
printf("Enter a number: ");
scanf("%d", &num);
printf("Multiplication Table for %d:\n", num);
for (i = 1; i <= 10; ++i) {
printf("%d x %d = %d\n", num, i, num * i);
}
return 0;
}
26. C Program to Print Fibonacci Series?
#include<stdio.h>
int main(){
int a,b, c , n , i;
printf("enter your range of fibonacci series:");
scanf("%d",&n);
a=0;
b=1;
for (i=1;i<=n;i++){
printf("%d\t",a);
c=a+b;
a=b;
b=c;
}
return 0;
}

27. C Program to Find LCM of Two Numbers?


#include <stdio.h>
int main()
{
int a, b, lcm;
printf("enter two numbers:");
scanf("%d %d",&a,&b);
for(lcm=1;lcm<=a*b;lcm++)
if(lcm%a==0 &&lcm%b==0)
break;
printf("\nLCM= %d",lcm);

return 0;
}
28. C Program to Check Armstrong Number?
#include<stdio.h>
int main(){
int n,arm=0,c,r;
printf("enter any number:");
scanf("%d",&n);
c=n;
while (n>0){
r=n%10;
arm=(r*r*r)+arm;
n=n/10;
}
if(c==arm)
printf("armstrong");
else
printf("not a armstrong number");
return 0;
}

29. C Program to Display Armstrong Numbers Between 1 to 100?


#include <stdio.h>
int main() {
int num, digit, sum = 0, temp;
printf("Armstrong numbers between 1 to 100:\n");
for(num = 1; num <= 100; num++) {
temp = num;
sum = 0;
while(temp != 0) {
digit = temp % 10;
sum += digit * digit * digit;
temp /= 10;
}
if(sum == num)
printf("%d\n", num);
}
return 0;
}
30. C Program to Display Armstrong Number Between Two Intervals ?
#include <stdio.h>
int main() {
int num, digit, sum = 0, temp;
printf("Armstrong numbers between given intervals :\n");
for(num = 100; num <= 500; num++) {
temp = num;
sum = 0;
while(temp != 0) {
digit = temp % 10;
sum += digit * digit * digit;
temp /= 10;
}
if(sum == num)
printf("%d\n", num);
}
return 0;
}

31. C Program to Reverse a Number?


#include <stdio.h>
int main(){
int a,r;
printf("Enter any number:");
scanf( "%d",&a);
while (a>0){
r=a%10;
printf("%d",r);
a=a/10;
}
return 0;
}
32. C Program to Check Whether a Number is a Palindrome or Not ?
#include <stdio.h>
int main() {
int num, reversedNum = 0, remainder, originalNum;
printf("Enter an integer: ");
scanf("%d", &num);
originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
if (originalNum == reversedNum) {
printf("Palindrome\n");
} else {
printf("Not Palindrome\n");
}
return 0;
}

33. C Program to Display Prime Numbers Between Intervals?


#include<stdio.h>
int main(){
int n1, n2,i,j;
printf("enter range:");
scanf("%d %d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;

}
if (i==j)
printf("%d \t ",j);
}
return 0;
}
34. C Program to Check whether the input number is a Neon Number?
#include <stdio.h>

int main() {
int num, square, sum = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
square = num * num; // Calculate the square of the number
// Calculate the sum of the digits of the square
while (square != 0) {
remainder = square % 10;
sum += remainder;
square /= 10;
}
// Check if the sum of digits equals the original number
if (sum == num) {
printf("%d is a Neon number.\n", num);
} else {
printf("%d is not a Neon number.\n", num);
}

return 0;
}

35. C Program to Find All Factors of a Natural Number?


#include <stdio.h>

int main() {
int num;

printf("Enter a number: ");


scanf("%d", &num);

printf("Factors of %d are: ", num);

for (int i = 1; i <= num; i++) {


if (num % i == 0) {
printf("%d ", i);
}
}

return 0;
}
36. C Program to Print Simple Pyramid Pattern ?
#include <stdio.h>

int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {


for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
printf("*");
}
printf("\n");
}

return 0;
}

37. C Program to Print Given Triangle ?


#include <stdio.h>

int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {


for (int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}

return 0;
}
38. C Program to Print 1800 Rotation of Simple Pyramid?
#include <stdio.h>
int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
printf("*");
}
printf("\n");
}

return 0;
}

39. C Program to Print Inverted Pyramid ?


#include <stdio.h>
int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

for (int i = rows; i >= 1; i--) {


for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
printf("*");
}
printf("\n");
}
return 0;
}
40. C Program to Print Number Pattern?
#include <stdio.h>
int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {


for (int j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}

return 0;
}

41. C Program to Print Character Pattern ?


#include <stdio.h>

int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {


for (int j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}

return 0;
}
42. C Program to Print Continuous Character Pattern?
#include <stdio.h>

int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

char ch = 'A';
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("%c ", ch);
ch++;
}
printf("\n");
}

return 0;
}
43. C Program to Print Pascal’s Pattern Triangle Pyramid ?
#include <stdio.h>
int factorial(int n) {
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
int main() {
int rows;

printf("Enter the number of rows: ");


scanf("%d", &rows);

for (int i = 0; i < rows; i++) {


for (int j = 0; j < rows - i; j++) {
printf(" ");
}

for (int j = 0; j <= i; j++) {


printf("%d ", factorial(i) / (factorial(j) * factorial(i - j)));
}
printf("\n");
}

return 0;
}
44. C Program to Display Prime Numbers Between Two Intervals Using Functions ?
#include <stdio.h>

int isPrime(int num) {


for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
return 0; // Not a prime number
}
}
return 1; // Prime number
}

int main() {
int start, end;

printf("Enter the start and end of the interval: ");


scanf("%d %d", &start, &end);

printf("Prime numbers between %d and %d are: \n", start, end);


for (int i = start; i <= end; i++) {
if (isPrime(i)) {
printf("%d ", i);
}
}

return 0;
}
45. C Program to Find All Roots of a Quadratic Equation?
#include <stdio.h>
#include <math.h>

int main() {
float a, b, c, discriminant, root1, root2;

printf("Enter coefficients a, b, and c: ");


scanf("%f %f %f", &a, &b, &c);

discriminant = b * b - 4 * a * c;

if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different: %.2f and %.2f\n", root1, root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("Root is real and same: %.2f\n", root1);
} else {
printf("Roots are complex.\n");
}

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy