Call Girls in Dwarka Mor Delhi Contact Us 9654467111
C programming codes for the class assignment
1. C Programming codes for the class Assignment
Problem 1
Write a program in C to initialize an array and then display it in reverse order.
2. We can solve this problem in two way
1.Using for loop
2. Using string type array
3. #include<stdio.h>
int main(void)
{
int s1[100];
int i,n,count=0;
printf("Enter size of array:n");
scanf("%d",&n);
printf("n Enter Numbers:n");
for(i=0; i<n ;i++)
{
printf("Element %dn ",count++);
scanf("%d ",&s1[i]);
}
printf("n Reverse is :n");
for(i=n-1;i>=0;i--)
{
printf("%d ",s1[i]);
}
return 0;
}
4. Using String type array
#include<stdio.h>
#include<string.h>
int main(void)
{
char s1[100];
printf("Enter a string:n");
gets(s1);
printf("n Reverse of string is %s
nn",strrev(s1));
return 0;
}
Notice that String type array
(string) works only if the data type
is char type. Otherwise it may go
wrong.
5. Problem-2
Write a Program in C to store n element in an array from
user and then find the maximum and minimum element.
6. Solve the ProblemUsing for loop and like the example in the book at page143
include <stdio.h>
#include <conio.h>
int main()
{
int s[1000];
int i,n,min,max;
int a=1;
printf("Enter size of the array :n ");
scanf("%d",&n);
printf("Enter elements in array :n ");
for(i=0; i<n; i++)
{
printf("Element %dn",a++);
scanf("%d",&s[i]);
}
min=max=s[0];
for(i=1; i<n; i++)
{
if(min>s[i])
min=s[i];
if(max<s[i])
max=s[i];
}
printf("nMinimum of array is : %d",min);
printf("nMaximum of array is : %dn",max);
return 0;
}
7. Problem-3
Write a program in C to store n element in an array from
user and then store even and odd in two different array
8. This problem may solve in two ways
Way-1: Using only for loop
Way-2 Using a conditional function
9. #include<stdio.h>
#include<conio.h>
int main()
{
int a[10000],b[10000],c[20000],i,n;
int l=0;
printf("Enter size of the array :n ");
scanf("%d", &n);
printf("Enter elements in array :n ");
for(i=0; i<n; i++)
{
printf("Element %dn",l++);
scanf("%d",&a[i]);
}
printf("n Original Array:n");
for(i=0; i<n; i++)
printf("%d ",a[i]);
for(i=0; i<n; i++)
b[i]=a[i];
printf("n Even n");
for(i=0;i<n;i++)
{
if(a[i]%2==0)
printf("%d ",b[i]);
}