0% found this document useful (0 votes)
36 views12 pages

Computational

The document contains 10 programming problems of varying complexity. The problems cover topics like functions, arrays, pointers, structures, matrices and string handling.

Uploaded by

Atharv Mandawkar
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)
36 views12 pages

Computational

The document contains 10 programming problems of varying complexity. The problems cover topics like functions, arrays, pointers, structures, matrices and string handling.

Uploaded by

Atharv Mandawkar
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/ 12

1)Write a program for calculate the sum of five subject marks, display sum and percentage.

#include <stdio.h>

main()

int sub1,sub2,sub3,sub4,sub5,sum;

float per;

printf("Enter marks of subject =");

scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);

sum=sub1+sub2+sub3+sub4+sub5;

per=sum/5.0;

printf("Sum of subject =%d",sum);

printf("Percentage =%f",per);

getch();

}
2)Write a program to find Armstrong number?

#include <stdio.h>

main()

int num, originalNum, remainder, result = 0;

printf("Enter a Number : ");

scanf("%d",&num);

originalNum=num;

while (originalNum!= 0)

remainder = originalNum % 10;

result +=remainder;

originalNum/=10;

if (result==num)

printf("%d is an Armstrong number.",num);

else

printf("%d is not an Armstrong number.",num);

getch();

}
3)Write a program to display following series.

112358

#include <stdio.h>

main()

int n=6,a=0,b=1,c,i;

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

if (i<=1)

c= i;

else{

c=a+b;

a=b;

b=c;

printf("%d ",c);

getch();

}
4)Write a program for switch case having following cases addition of two numbers, subtraction of two numbers,
multiplication of two numbers, division of two numbers, default case "Please enter the correct case".

#include <stdio.h>

int main()

int choice;

float num1, num2, result;

printf("Menu:\n");

printf("1. Addition\n");

printf("2. Subtraction\n");

printf("3. Multiplication\n");

printf("4. Division\n");

printf("Enter your choice (1-4): ");

scanf("%d", &choice);

printf("Enter two numbers: ");

scanf("%f %f", &num1, &num2);

switch(choice)

case 1:

result = num1 + num2;

printf("Addition Result: %.2f\n", result);

break;

case 2:

result = num1 - num2;

printf("Subtraction Result: %.2f\n", result);

break;

case 3:

result = num1 * num2;

printf("Multiplication Result: %.2f\n", result);

break;

case 4:

if (num2 != 0)

result = num1 / num2;

printf("Division Result: %.2f\n", result);

else

{
printf("Error! Division by zero.\n");

break;

default:

printf("Please enter the correct case 1 and 4.\n");

getch();

}
5)Write a program to diplay following series.

22

333

4444

55555

#include <stdio.h>

main()

int i,j;

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

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

printf("%d",i);

printf("\n");

getch();

}
6)Write a program to calculate area and circumference of circle using function (call by value with argument).

#include <stdio.h>

#define PI 3.14159

float calculateArea(float radius)

return PI * radius * radius;

float calculateCircumference(float radius)

return 2 * PI * radius;

int main()

float radius;

printf("Enter the radius of the circle: ");

scanf("%f", &radius);

float area = calculateArea(radius);

float circumference = calculateCircumference(radius);

printf("Area of the circle: %.2f\n", area);

printf("Circumference of the circle: %.2f\n", circumference);

return 0;

}
7)Write a program for pointer.

#include <stdio.h>

main()

int a=10;

int *p=&a;

int **q=&p;

printf("A =%d",a);

printf("A =%d",*p);

printf("A =%d",**q);

getch();

}
8)Write a program to count the length of string without using library function of string.

#include <stdio.h>

main()

char str[100];

int length = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin);

while (str[length] != '\0')

length++;

printf("Length of the string: %d\n", length);

getch();

}
9)Write a pragram to calculate the sum of two matrix, each matrix have three row and three coloumn.

#include <stdio.h>

main()

int matrix1[3][3], matrix2[3][3], sum[3][3];

int i, j;

printf("Enter elements of first matrix:\n");

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

for (j = 0; j < 3; j++)

printf("Enter element a%d%d: ", i + 1, j + 1);

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

printf("\nEnter elements of second matrix:\n");

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

for (j = 0; j < 3; j++)

printf("Enter element b%d%d: ", i + 1, j + 1);

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

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

for (j = 0; j < 3; j++)

sum[i][j] = matrix1[i][j] + matrix2[i][j];

printf("\nSum of the matrices:\n");

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

for (j = 0; j < 3; j++)

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

printf("\n");

getch();

}
10)Write a program for structure having student name, variable name of structure are name, rollno, percentage.

#include <stdio.h>

struct student

char name[50];

int rollno;

float percentage;

};

int main()

struct student stu;

printf("Enter student name: ");

scanf("%s", stu.name);

printf("Enter student roll number: ");

scanf("%d", &stu.rollno);

printf("Enter student percentage: ");

scanf("%f", &stu.percentage);

printf("\nStudent Details\n");

printf("Name: %s\n", stu.name);

printf("Roll Number: %d\n", stu.rollno);

printf("Percentage: %.2f\n", stu.percentage);

return 0;

You might also like