0% found this document useful (0 votes)
5 views7 pages

CS Assignment

The document contains multiple C programming assignments with code snippets for various tasks. These tasks include calculating the sum of a series, generating patterns, checking for perfect squares, calculating average marks, counting even and odd numbers, and string manipulation. Each assignment is structured with a question number and corresponding code implementation.

Uploaded by

adityaparmar.cse
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)
5 views7 pages

CS Assignment

The document contains multiple C programming assignments with code snippets for various tasks. These tasks include calculating the sum of a series, generating patterns, checking for perfect squares, calculating average marks, counting even and odd numbers, and string manipulation. Each assignment is structured with a question number and corresponding code implementation.

Uploaded by

adityaparmar.cse
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

Assignment 4

Q1. #include<stdio.h>

int main()
{
int n;
float ans;
printf("Enter the number n :");
scanf("%d", &n);

ans = (n*(n+1)/2);

printf("The sum of the series is %f", 1/ans);

return 0;
}

Q2. #include<stdio.h>

int main()
{
int i,j,k=0;

for(i=0;i<4;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ", k);
k++;
}

printf("\n");
}

return 0;
}
Q4. #include<stdio.h>

int main()
{
int n,i,flag=0;
printf("Enter the number :");
scanf("%d", &n);

for(i=2;i<n;i++)
{
if(i*i==n)
{
flag = 1;
break;
}
}

if(flag==1)
{
printf("Perfect Square");
}
else
{
printf("Not a Perfect Square");
}

return 0;
}

Q5. #include<stdio.h>

int main()
{
int i,j;
int ans = 65;

for(i=0;i<4;i++)
{
for(j=0;j<=i;j++)
{
printf("%c ", ans);
}
ans++;
printf("\n");
}

return 0;
}
Assignment 5
Q1. #include<stdio.h>
int main()
{
float arr[5],avg,sum=0;
int i,j;
printf("Enter Marks of the Students :");
for(i=0;i<5;i++)
{
scanf("%f ", &arr[i]);
sum = sum +arr[i];
}

avg = sum/5;

printf("Total Marks of 5 Students is : %f\n", sum);


printf("Average Marks of 5 Students is : %f\n", avg);

return 0;

Q2. #include<stdio.h>
int main()
{
int arr[10], i,j,count_even=0,count_odd=0;
printf("Enter the numbers :");
for(i=0;i<10;i++)
{
scanf("%d", &arr[i]);
if(arr[i]%2==0)
{
count_even++;
}
else
{
count_odd++;
}
}

printf("Number of Even Digits are : %d\n", count_even);


printf("Number of Odd Digits are : %d\n", count_odd);

return 0;
}
Q3. #include<stdio.h>
int main()
{
int arr1[5], arr2[5],arr3[2],i,j,sum1=0,sum2=0;

printf("Enter Array 1 :");


for(i=0;i<5;i++)
{
scanf("%d", &arr1[i]);
sum1 = sum1 + arr1[i];
}
printf("Enter Array 2 :");
for(i=0;i<5;i++)
{
scanf("%d", &arr2[i]);
sum2 = sum2 + arr2[i];
}

arr3[0] = sum1;
arr3[1] = sum2;
for(i=0;i<2;i++)
{
printf("%d ", arr3[i]);
}

return 0;
}
Assignment 6
Q1. #include<stdio.h>
int main()
{
char word[20];

printf("Enter the String :");


scanf("%s",&word);

printf("%s", word);

return 0;

Q2. #include<stdio.h>
#include<string.h>
int main()
{
char word[20];

printf("Enter the String :");


scanf("%s",&word);

printf("%zu", strlen(word));

return 0;

}
Q3. #include<stdio.h>
#include<string.h>
int main()
{
char word[20],i;

printf("Enter the String :");


scanf("%s",&word);

for(i=0;word[i]!='\0';i++)
{
if(word[i]>='a' && word[i]<='z')
{
word[i] = word[i] - 32;
}
}

printf("%s", word);

return 0;

Q4. #include<stdio.h>
#include<string.h>
int main()
{
char word[20],i;

printf("Enter the String :");


scanf("%s",&word);

for(i=0;word[i]!='\0';i++)
{
if(word[i]>='A' && word[i]<='Z')
{
word[i] = word[i] + 32;
}
}

printf("%s", word);

return 0;

}
Q5. #include<stdio.h>
#include<string.h>
int main()
{
char word1[20],word2[20],i;

printf("Enter the String 1 :");


scanf("%s",&word1);

printf("Enter the String 2 :");


scanf("%s",&word2);

printf("Concatenated string is %s", strcat(word1,word2));

return 0;

You might also like