C Program Rcu
C Program Rcu
PART A
1.Program to read radius of a circle and to find area and circumference
#include<stdio.h>
void main()
{
float radius, area,circumference;
printf("\nEnter the radius of Circle : ");
scanf("%f", &radius);
area = 3.14 * radius * radius;
circumference=2*3.14*radius;
printf("\nArea of Circle : %f", area);
printf("\nCircumference of Circle : %f", circumference);
}
else
printf("%d is the largest number.", n3);
void main ()
{
float a=1.8;
float x=100;
printf ("ceil = %lf\n", ceil(a));
printf("floor = %lf\n", floor(a));
printf("The absolute value of %f is %lf\n", a, fabs(a));
printf("log10(%f) = %lf\n", x, log10(x));
printf("Square root of %lf is %lf\n", x, sqrt(x) );
printf("Value 5.0 ^ 3 = %lf\n", pow(5, 3));
printf("The cosine of %lf is %lf degrees\n", x, cos(x));
}
0
1
1
2
3
5
10
5
roots are equal =-1.000000 -1.000000
#include <stdio.h>
void main ()
{
int arr[20], i, j, k, size;
printf (" \n Array elements after deletion of the duplicate elements: ");
for ( i = 0; i < size; i++)
{
printf (" %d \t", arr[i]);
}
}
A = B;
B = temp;
Before swapping A= 5 B= 8
After swapping A= 8 B= 5
#include<stdio.h>
void main()
{
char str[20];
int i, vowels, consonants, digits, spaces, symbols;
vowels = consonants = digits = spaces = symbols = 0;
printf("Enter the string\n");
gets(str);
for(i=0; str[i]!='\0';i++)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U')
{
vowels++;
}
else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
{
consonants++;
}
else if(str[i]>='0' && str[i]<='9')
#include <stdio.h>
void main()
{
char str[10], Rev[10];
int i, j=0,count=0;
printf("\n Please Enter any String :");
scanf("%s",str);
#include <stdio.h>
void main()
{
char str[10];
int count=0;
printf("\n Please Enter any String :");
gets(str);
String length = 8
#include <stdio.h>
#include <string.h>
void main()
{
char str1[20] = "Peopletree",str2[20]="BCA";
printf("Length of string %s is: %ld\n",str1,strlen(str1));
printf("Length of string %s is: %ld\n",str2,strlen(str2));
printf("First string after concatenation: %s\n", strcat(str1,str2));
printf("First string after copying: %s\n", strcpy(str1,str2));
#include<stdio.h>
void main( )
{
int a[10][10], m,i,j, sum;
printf ("\n Enter order of the square matrix :") ;
scanf ("%d", &m);
printf ("\n Enter the matrix \n");
for( i=0; i<m;i++)
for ( j=0; j<m; j++)
scanf ("%d", &a[i ][ j ]);
printf("\nGiven matrix is\n");
for( i=0; i<m;i++)
{
for ( j=0; j<m; j++)
printf("%d\t", a[i ][ j ]);
printf("\n");
}
sum = 0;
for ( i=0; i<m; i++)
sum = sum + a[i ][ i ];
printf ("\n trace of the matrix = %d", sum);
}
Given matrix is
1 2 3
4 5 6
7 8 9
#include<stdio.h>
void main()
{
int m, n, i, j, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
Enter elements:
2222
Enter elements:
2222
Output Matrix:
8 8
8 8
#include <stdio.h>
int isprime(int n)
{
int i;
for(i=2;i<=n/2;i++)
{
if(n%i==0)
return 0;
}
return 1;
}
void main()
{
int num,res=0;
printf("Enter a number: ");
scanf("%d",&num);
if(isprime(num))
printf("\n%d is a prime number",num);
else
printf("\n%d is not a prime number",num);
}
Enter a number: 13
13 is a prime number
include <stdio.h>
struct student
{
char firstName[50];
int roll;
int marks;
} s[10];
void main()
{
int i,n;
printf("Enter no. of students:");
scanf("%d",&n);
printf("\nEnter information of students:\n");
// storing information
for (i = 0; i < n; i++)
{
printf("Enter the roll no. : ");
scanf("%d",&s[i].roll);
printf("Enter name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
// displaying information
for (i = 0; i < n; i++)
{
printf("\nRoll number: %d\n",s[i].roll);
printf("First name: ");
puts(s[i].firstName);
printf("Marks: %d", s[i].marks);
printf("\n");
}
Displaying Information:
Roll number: 1
First name: aman
Marks: 17
Roll number: 2
First name: amit
Marks: 20
struct Employee1
{
char emp_name[20];
int emp_no;
float salary;
};
union Employee2
{
char emp_name[20];
int emp_no;
float salary;
};
void main()
{
struct Employee1 s;
union Employee2 u;
printf("Size of structure =%ld\n",sizeof(s));
printf("Size of union =%ld\n",sizeof(u));
printf("\n Enter the name ,number and salary of employee1\n");
scanf("%s %d %f",s.emp_name,&s.emp_no,&s.salary);