Ca some one please help me with aC code to allow user enter
numbers from 1 to 20 without repeating and prnt the sum of
those numbers
thnx
Answer Posted / sanjay bhosale
/ Duplicate.cpp : main project file.
// Program : To find duplicate no in array by traversing it only once.
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
using namespace System;
int main(array<System::String ^> ^args)
{
int *arr;
int val = 0;
int size = 0;
printf(" \n Enter the no of elements in array :");
scanf_s("%d",&size);
arr = (int *)malloc(sizeof(int)*size);
printf("\n Enter elements in the range 1 to %d:",size);
for(int i=0;i<size;i++)
{
scanf_s("%d",&val);
if(val<1 && val>=size)
{
printf("\n enter element again :\t");
i--;
}
else
*(arr+i) = val;
}
int sum = 0;
getchar();
printf("Array is :\n");
for(int i=0;i<size;i++)
{
printf("\t %d",arr[i]);
sum+= arr[i];
}
getchar();
printf("\n sum : %d",sum);
int diff = sum-(size*(size-1)/2.0);
printf(" Duplicate element is :%d\n",diff);
getchar();
return 0;
}
Might this help you........
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How many types of arrays are there in c?
What does 4d mean in c?
can any one provide me the notes of data structure for ignou cs-62 paper
What is the advantage of using #define to declare a constant?
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
Is there any possibility to create customized header file with c programming language?
What are the rules for identifiers in c?
What are the types of type specifiers?
What is extern storage class in c?
Explain heap and queue.
What is a const pointer?
When c language was developed?
Is sizeof a keyword in c?
Why does the call char scanf work?
What are the data types present in c?