Loading....
Coupon Accepted Successfully!

 

Example-1

#include <stdio.h>
main()
{
int size=50;
float marks[size];
for(int i = 0;i<size;i++)
{
printf(“\nEnter Marks of %d Student = ”,(i+1));
scanf(“%f”,&marks[i]);
}
for(int i = 0;i<size;i++)
{
printf("\nMarks of Student %d = %d",(i+1),marks[i]);
}
}
/*---------------Output----------------------------*/
Enter Marks of 1 Student = 395.25
Enter Marks of 2 Student = 265.25
Enter Marks of 3 Student = 451.11
.
.
.
.
Enter Marks of 50 Student = 451.25
Marks of Student 1 = 395.25
Marks of Student 2 = 265.25
Marks of Student 3 = 451.11
.
.
.
.
Marks of Student 50 = 451.25
 

Example 2

A complete C program for implementing a list with operations for reading values of the elements of the list and displaying them is given here:

#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
int a[5],i,sum=0;
clrscr();
printf("Enter the elements of array \n");
read(a,5); /*read the array*/
printf("The array elements are \n");
dis(a,5);
}
void read(int c[],int i)
{
int j;
 
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
{
int j;
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}

Input
Enter the elements of the first array
15
30
45
60
75

/*-------------Output--------------------*/
The elements of the first array are
15 30 45 60 75
 

Example 3

Addition of the elements of the list of Array

#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
int a[5],i,sum=0;
clrscr();
printf("Enter the elements of list \n");
read(a,5); /*read the list*/
printf("The list elements are \n");
 
dis(a,5);
for(i=0;i<5;i++)
{
sum+=a[i];
}
printf("The sum of the elements of the list is %d\n",sum);
getch();
}
void read(int c[],int i)
{
int j;
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
{
int j;
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}

Input
Enter the elements of the first array
15
30
45
60
75

Output
The elements of the first array are
15 30 45 60 75
The sum of the elements of an array is 225.
 

Example 4

Suppose the first list is
1
2
3
4
5

and the second list is
5
6
8
9
10

The first element of first list is added to the first element of the second list, and the result
of the addition is the first element of the third list.

In this example, 5 is added to 1, and the first element of third list is 6.
This step is repeated for all the elements of the lists and the resultant list after the addition
is
6
8
11
13
15

#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
void add(int *,int *,int * ,int);
int a[5],b[5],c[5],i;
clrscr();
printf("Enter the elements of first list \n");
read(a,5); /*read the first list*/
printf("The elements of first list are \n");
dis(a,5); /*Display the first list*/
printf("Enter the elements of second list \n");
read(b,5); /*read the second list*/
printf("The elements of second list are \n");
dis(b,5); /*Display the second list*/
add(a,b,c,i);
printf("The resultant list is \n");
dis(c,5);
getch();
}
void add(int a[],int b[],int c[],int i)
{
for(i=0;i<5;i++)
{
c[i]=a[i]+b[i];
}
}
void read(int c[],int i)
{
int j;
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
{
int j;
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}

 

Example 5

The following program makes a reverse version of the list of Array.

#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
void inverse(int *,int);
int a[5],i;
clrscr();
read(a,5);
dis(a,5);
inverse(a,5);
dis(a,5);
getch();
}
void read(int c[],int i)
{
int j;
printf("Enter the list \n");
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
{
int j;
printf("The list is \n");
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}
void inverse(int inver_a[],int j)
{
int i,temp;
j-;
for(i=0;i<(j/2);i++)
{
temp=inver_a[i];
inver_a[i]=inver_a[j];
inver_a[j]=temp;
j-;
}
}

Input
Enter the list
10
20
30
40
50

Output
The list is
10 20 30 40 50
The inverse of the list is
50 40 30 20 10
 

Example 6

This is another version of an inverse program, in which another list is used to hold the reversed list.

#include<stdio.h>
#include<conio.h>
void main()
{
void read(int *,int);
void dis(int *,int);
void inverse(int *,int *,int);
int a[5],b[5];
clrscr();
read(a,5);
dis(a,5);
inverse(a,b,5);
dis(b,5);
getch();
}
void read(int c[],int i)
{
int j;
printf("Enter the list \n");
for(j=0;j<i;j++)
scanf("%d",&c[j]);
fflush(stdin);
}
void dis(int d[],int i)
 
{
int j;
printf("The list is \n");
for(j=0;j<i;j++)
printf("%d ",d[j]);
printf("\n");
}
void inverse(int a[],int inverse_b[],int j)
{
int i,k;
k=j-1;
for(i=0;i<j;i++)
{
inverse_b[i]=a[k];
;
}
}

Input
Enter the list
10
20
30
40
50

Output
The list is
10 20 30 40 50
The inverse of the list is
50 40 30 20 10
 

Example 7

Program to check string is palindrome or not
#include<stdio.h>
void main()
{
char string[80];
printf(“Enter string (max 79 character ) : ”);
gets(string);
len=strlen(string);
for(int i=0, j=len-1; i<len/2; i++,j--)
{
if(string[i]!=string[j])
{
flag=0;
break;
}
}
if(flag==0)
printf(“Not palindrome”);
else
printf(“Palindrome ”);
}

Input
Enter string(max, 79 characters) : computer

Output
Not palindrome

Input
Enter string(max, 79 characters) : computer

Output
Palindrome
 




Test Your Skills Now!
Take a Quiz now
Reviewer Name