245 subscribers
6 photos
3 files
4 links
This group will help beginners to learn programming in C language.

Discussion: @c_coding_discussion
Download Telegram
# Explanation |Quiz. #6|
Here ,ptr is a pointer,and it'll take the address of variable var i.e it'll store 5, then in printf statement, the value will be print first and then would be increment, so the correct answer is 5.
#DSA_Series
50. C program to delete an element in array from a given index.

#include <stdio.h>

void display(int *arr, int size){
for(int i=0; i<=size; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
int delInd_arr(int *arr,int size, int ind){
if(size==-1){
printf("Underflow!");
return -1;
}
else{
for(int i=ind; i<=size; i++){
arr[i] = arr[i+1];
}
return 1;
}
}

int main()
{
int arr[100] = {11,22,65,72};
int size = 3, index = 1;
printf("Before deletion\n");
display(arr, size);
delInd_arr(arr,size, index);
size -= 1;
printf("After deletion\n");
display(arr, size);
return 0;
}
51. C program to swap three integers
#include<stdio.h>

int main()
{
int a,b,c;
int temp1, temp2;
scanf("%d %d %d",&a,&b,&c);
temp1=a;
a=b;
b=temp1;
temp2=a;
a=c;
c=temp2;
printf("%d %d %d",a,b,c);
return 0;
}
53. C program to swap three interes without using external variable.
#include<stdio.h>

int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
a=a+b;
b=a-b;
a=a-b;

a=a+c;
c=a-c;
a=a-c;
printf("%d %d %d",a,b,c);
return 0;
}
54. C program to find sum of first five prime numbers.
#include <stdio.h>
int isprime(int j){
int p=0;
for(int i = 2 ; i <= j/2; i++){
if(j%i == 0){
p = 1;
}
}
if(p == 0){
return 1;
}
else
return 0;
}
int main(void) {
int num = 1;
int i=0, j= 1;
int sum = 0;
while(num<=5){
j++;
if(isprime(j)){
sum += j;
num++;
}
}
printf("sum =%d",sum);
return 0;
}
|Quiz. #7|
What will be the output?
Anonymous Quiz
12%
5
43%
7
27%
1
18%
Error!
Do you want another group for doubts or queries about these programs and C language?
Anonymous Poll
87%
Yes
13%
No
55. C program to print Fibonacci series of n terms.
#include <stdio.h>

int main(){
int n,n1=0,n3,n2=1;
scanf("%d",&n);
for(int k=0; k<n; k++){
if(k<=1)
n3=k;
else{
n3=n1+n2;
n1=n2;
n2=n3;
}
printf("%d ",n3);
}
return 0;
}
56. C program to find the term of Fibonacci series on a given index.
#include <stdio.h>
//0 1 1 2 3 5 8 13......n
int fib(int n){
if(n==1 || n==0)
{
return 1;
}
else{
return fib(n-2) + fib(n-1);
}
}

int main(){
int n, fTerm;
scanf("%d",&n);

fTerm=fib(n-1);
printf("%d",fTerm);
return 0;
}
57. C program to check whether a character is a Vowel / Constant / Number / Spacial symbol / space of a given string.
#include<stdio.h>
#include<string.h>
int main()
{
char s[200];
int len;
printf("enter a string: ");
scanf("%[^\n]%*c",&s);
len=strlen(s);

for(int p=0; p< len; p++)
{
if(s[p]==97 s[p]==101 s[p]==105 s[p]==111 s[p]==117)
{
printf("%c is a vowel\n",s[p]);
continue;
}

else if(s[p]==' '){
printf("space\n");
}
else if(s[p] >= 48 && s[p] <= 57)
{
printf("%c is a number\n", s[p]);
}
else if((s[p]>=33 && s[p]<= 47) (s[p]>= 58 && s[p]<= 64) (s[p]>= 91 && s[p]<= 96) || (s[p] >= 123 && s[p] <= 126))
{
printf("%c is a special symbol\n",s[p]);
}
else{
printf("%c is a constent\n",s[p]);
}
}
return 0;
}
58. C program to print sparse matrix of a given matrix.

#include<stdio.h>

int main()
{
int a[10][10],spmt[10][3],m,n,temp=0,i,j;
printf("Enter the range of matix: ");
scanf("%d%d",&n,&m);
printf("enter the elements of the matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("your matrix matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=0)
{
spmt[temp][0]=a[i][j];
spmt[temp][1]=i;
spmt[temp][2]=j;
temp++;
}
}
}
printf("\nThe sparse matrix:\n");
for(i=0;i<temp;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",spmt[i][j]);
}
printf("\n");
}
return 0;
}
C Coding pinned «C_Coding_Discussion This is only for discussion about C programming.. https://t.me/c_coding_discussion»
59. C program to reverse a single string without using 'strrev()' library function.
#include <stdio.h>

int main()
{
int n;
printf("enter the length of the string: ");
scanf("%d", &n);
char str[n];
printf("enter the string\n");

for(int j=0; j<=n; j++){
scanf("%c", &str[j]);
}
for(int i =n; i>=0; --i){
printf("%c", str[i]);
}
return 0;
}
60. C program to find roots of quadratic equation.

#include <stdio.h>
#include <math.h>

int main(){
int a,b,c;
printf("enter the value of ab and c: ");
scanf("%d %d %d",&a, &b, &c);

float r1, r2;
float s = (b*b) - 4 * a * c;

if(s>0){
printf("roots are real:\n");
r1 = ((-b + sqrt(s)) / (2*a));
r2 = ((-b - sqrt(s)) / (2*a));
printf("(%.f, %.f)", r1, r2);
}
else{
printf("roots are imaginary");
r1 = -b / 2*a;
r2 = sqrt(s) / 2*a;
printf("(%.f+%.fi), (%.f+%.fi)",r1, r2, r1, r2);
}

return 0;
}
|Quiz. #8|
What is the output?
#include <stdio.h> int main() { printf ("%d & %d", (36 & 28), (36 | 28)); return 0; }
Final Results
13%
36 28
16%
36 & 28
29%
4 & 60
42%
Error!!
#Explanation |Quiz. #8|
First of all, for both operations we have to convert these numbers in the of 8 bits(binary form) then apply to operations of '&' and '|' they are:
> & Will return 1 when both conditions are true i.e 1, otherwise it will return false i.e 0.
> | Will return 1 when any one condition is true I.e 1, otherwise it'll return false I.e 0
____________________________
(2^n..........32 16 8 4 2 1)
36 & 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 0 0 0 1 0 0 -> 4 ans.
36 | 28:
36 -> 0 0 1 0 0 1 0 0
28 -> 0 0 0 1 1 1 0 0
______________
0 0 1 1 1 1 0 0 -> 60 ans.


Hope you all understood.
Happy coding :)
61. C program to find number of characters and number of spaces in a given string.

#include <stdio.h>
int main()
{
char str[]="do not do everything for something, just do something you will achieve everything\n";
printf("%s\n", str);
int countNum=0, countSp=0;
for(int a=0; a< strlen(str); a++)
{
if(str[a] != ' ') {
countNum++;
}
else{
countSp++;
}
}
printf("number of characters is: %d\nnumber of spaces is: %d\n",countNum, countSp);
return 0;
}
👍1
|Quiz. #9|
What is the output?
#include<stdio.h> int main(){ int ar[6]={4,1,9,8,5,9,5}; int *ptr1=ar; int *ptr2=&ar[4]; int res=ptr2 - ptr1; printf("%d",ar[res]); return 0; }
Anonymous Quiz
21%
1
21%
4
34%
5
23%
Error!
62. C program to compare first n characters of two given strings.
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100], str2[100];
int n, cmp;
printf("enter first steing: ");
scanf("%[^\n]%*c", &str1);
printf("enter second string: ");
scanf("%[^\n]%*c", &str2);
printf("%s \n%s\n", str1, str2);

printf("enter number of characters: ");
scanf("%d", &n);

cmp=strncmp(str1, str2, n);
if(cmp==0)
printf("%d characters of these strings are equal",n);
else
printf("not equal");
return 0;
}