Computational
Computational
#include <stdio.h>
main()
int sub1,sub2,sub3,sub4,sub5,sum;
float per;
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
sum=sub1+sub2+sub3+sub4+sub5;
per=sum/5.0;
printf("Percentage =%f",per);
getch();
}
2)Write a program to find Armstrong number?
#include <stdio.h>
main()
scanf("%d",&num);
originalNum=num;
while (originalNum!= 0)
result +=remainder;
originalNum/=10;
if (result==num)
else
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;
printf("Menu:\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
scanf("%d", &choice);
switch(choice)
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
if (num2 != 0)
else
{
printf("Error! Division by zero.\n");
break;
default:
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
return 2 * PI * radius;
int main()
float radius;
scanf("%f", &radius);
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;
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 i, j;
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][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()
scanf("%s", stu.name);
scanf("%d", &stu.rollno);
scanf("%f", &stu.percentage);
printf("\nStudent Details\n");
return 0;